简体   繁体   中英

Using string inside ShareActionProvider share intent

I'm trying to get ShareActionProvider to work and I've run into the following problem:

This code works:

      Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, "Text I want to share");

    MenuItem shareItem = menu.findItem(R.id.share);
    mShareActionProvider = (ShareActionProvider) shareItem.getActionProvider();
    mShareActionProvider.setShareIntent(shareIntent);

But this doesn't:

      Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());

    MenuItem shareItem = menu.findItem(R.id.share);
    mShareActionProvider = (ShareActionProvider) shareItem.getActionProvider();
    mShareActionProvider.setShareIntent(shareIntent);

Why is that?

I'm not sure, but try

shareIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl().toString());

instead of

shareIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM