下面列出了android.support.v7.widget.ShareActionProvider#setShareIntent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate the menu; this adds items to the action bar if it is present.
inflater.inflate(R.menu.detailfragment, menu);
// Retrieve the share menu item
MenuItem menuItem = menu.findItem(R.id.action_share);
// Get the provider and hold onto it to set/change the share intent.
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);
// If onLoadFinished happens before this, we can go ahead and set the share intent now.
if (mForecast != null) {
mShareActionProvider.setShareIntent(createShareForecastIntent());
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.removeGroup(R.id.browser);
getMenuInflater().inflate(R.menu.menu_browser, menu);
String shareContent = String.format("%s %s ", getTitle() + "", url + "");
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, shareContent);
MenuItem shareItem = menu.findItem(R.id.share);
ShareActionProvider shareProvider =
(ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
shareProvider.setShareHistoryFileName("channe_share.xml");
shareProvider.setShareIntent(shareIntent);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.detail, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.menu_item_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(getDefaultShareIntent());
}
else {
Log.d(LOG_TAG, "ShareActionProvider is null");
}
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.share_menu, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.action_share);
// Fetch ShareActionProvider
ShareActionProvider shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
if (shareActionProvider == null)
{
Log.w(TAG, "Failed to find share action provider");
return false;
}
if(receiptFilename == null)
{
Log.w(TAG, "No receipt to share");
return false;
}
Intent shareIntent = new Intent(Intent.ACTION_SEND);
// Determine mimetype of image
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inJustDecodeBounds = true;
BitmapFactory.decodeFile(receiptFilename, opt);
shareIntent.setType(opt.outMimeType);
Uri outputUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID, new File(receiptFilename));
shareIntent.putExtra(Intent.EXTRA_STREAM, outputUri);
// set flag to give temporary permission to external app to use the FileProvider
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareActionProvider.setShareIntent(shareIntent);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_device_detail, menu);
MenuItem menuItem = menu.findItem(R.id.action_share);
shareIntent = new Intent(Intent.ACTION_SEND)
.setType("text/plain");
ShareActionProvider provider =
(ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);
provider.setShareIntent(shareIntent);
return true;
}
private void initShareActionProvider(Menu menu) {
MenuItem shareMenuItem = menu.findItem(R.id.action_share);
ShareActionProvider actionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareMenuItem);
Intent shareIntent = new Intent(Intent.ACTION_VIEW);
shareIntent.setType(catImage.getType());
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(catImage.getLink()));
actionProvider.setShareIntent(shareIntent);
actionProvider.setOnShareTargetSelectedListener((source, intent) -> {
trackSharingAction(analyticsTrackerHelper, AnalyticsTags.CATEGORY_ACTION, AnalyticsTags.ACTION_SHARE);
return true;
});
}
@Override
public boolean onCreateOptionsMenu (Menu menu) {
getMenuInflater ().inflate (R.menu.collection_menu, menu);
MenuItem item = menu.findItem (R.id.menu_collection_share);
ShareActionProvider shareActionProvider = new ShareActionProvider (this);
shareActionProvider.setShareIntent (getShareIntent ());
MenuItemCompat.setActionProvider (item, shareActionProvider);
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item = menu.findItem(R.id.menu_share);
ShareActionProvider mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "https://github.com/dexlex/DexMovingImageView");
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Moving ImageView on GitHub");
sendIntent.setType("text/plain");
mShareActionProvider.setShareIntent(sendIntent);
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_msg_parse, menu);
MenuItem item = menu.findItem(R.id.menu_share_msgs);
ShareActionProvider sp = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(mHtml));
String subject = getString(R.string.app_name) + ": " + mActivityName +
": " + mMsgName;
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.setType("text/html");
sp.setShareIntent(sendIntent);
return true;
}