Issue
I have tried like following code to get share button:
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, url);
try {
startActivity(Intent.createChooser(intent, "Select an action"));
} catch (android.content.ActivityNotFoundException ex) {
// (handle error)
}
But this is giving me list of share options ON START
when I start my app.
I want it when I click on "share button" like below image.
How can I modify my code?
Solution
I resolved it with following code.
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
//add item menu
getMenuInflater().inflate(R.menu.main, menu);
//share new code
MenuItem shareItem = (MenuItem) menu.findItem(R.id.menu_item_share);
ShareActionProvider mShare = (ShareActionProvider)shareItem.getActionProvider();
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "text to share");
mShare.setShareIntent(shareIntent);
return true;
}
Answered By - Neo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.