Java Code Examples for android.support.v7.widget.ShareActionProvider#setShareIntent()

The following examples show how to use android.support.v7.widget.ShareActionProvider#setShareIntent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetailFragment.java    From Krishi-Seva with MIT License 6 votes vote down vote up
@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());
    }
}
 
Example 2
Source File: BrowserActivity.java    From TLint with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: DetailActivity.java    From android-weather with MIT License 6 votes vote down vote up
@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;
}
 
Example 4
Source File: ReceiptViewActivity.java    From budget-watch with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: DeviceDetailActivity.java    From device-database with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: CatViewerActivity.java    From android-aop-analytics with Apache License 2.0 5 votes vote down vote up
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;
    });
}
 
Example 7
Source File: CollectionActivity.java    From Jager with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 8
Source File: MainActivity.java    From DexMovingImageView with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: MsgParseActivity.java    From smartcard-reader with GNU General Public License v3.0 5 votes vote down vote up
@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;
}