@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.diff_commits, menu); MenuItem item = menu.findItem(R.id.action_share_diff); ShareActionProvider shareActionProvider = (ShareActionProvider) item.getActionProvider(); final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri futurePathName = Uri.fromFile(sharedDiffPathName()); shareIntent.putExtra(Intent.EXTRA_STREAM, futurePathName); shareIntent.setData(futurePathName); shareIntent.setType("text/x-patch"); shareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener () { public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { try { File diff = sharedDiffPathName(); saveDiff(new FileOutputStream(diff)); } catch (IOException e) { showToastMessage(R.string.alert_file_creation_failure); } return false; } }); shareActionProvider.setShareIntent(shareIntent); return true; }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.diff_commits, menu); MenuItem item = menu.findItem(R.id.action_share_diff); ShareActionProvider shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item); final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri futurePathName = Uri.fromFile(sharedDiffPathName()); shareIntent.putExtra(Intent.EXTRA_STREAM, futurePathName); shareIntent.setData(futurePathName); shareIntent.setType("text/x-patch"); shareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener () { public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { try { File diff = sharedDiffPathName(); saveDiff(new FileOutputStream(diff)); } catch (IOException e) { showToastMessage(R.string.alert_file_creation_failure); } return false; } }); shareActionProvider.setShareIntent(shareIntent); return true; }