Java源码示例:androidx.appcompat.widget.ShareActionProvider

示例1
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.log_list, menu);

    MenuItem switchLog = menu.findItem(R.id.switch_logs);
    switchLog.setTitle(mSyncthingLog ? R.string.view_android_log : R.string.view_syncthing_log);

    // Add the share button
    MenuItem shareItem = menu.findItem(R.id.menu_share);
    ShareActionProvider actionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
    mShareIntent = new Intent();
    mShareIntent.setAction(Intent.ACTION_SEND);
    mShareIntent.setType("text/plain");
    mShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, mLog.getText());
    actionProvider.setShareIntent(mShareIntent);

    return true;
}
 
示例2
private void setSendMenuIntent()
{
    if (mContentSet != null && mModel != null && mToolBar != null && mToolBar.getMenu() != null)
    {
        MenuItem shareItem = mToolBar.getMenu().findItem(R.id.opentasks_send_task);
        if (shareItem != null)
        {
            ShareActionProvider actionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
            Intent shareIntent = new ShareIntentFactory().create(mContentSet, mModel, mAppContext);
            actionProvider.setShareIntent(shareIntent);
        }
    }
}