I have this intent
Button share = (Button)findViewById(R.id.share);
share.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
//createShareIntent( );
}
});
and these two methods in the class:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.layout.menu, menu);
MenuItem item = menu.findItem(R.id.menu_item_share);
myShareActionProvider = (ShareActionProvider)item.getActionProvider();
myShareActionProvider.setShareHistoryFileName(
ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
myShareActionProvider.setShareIntent(createShareIntent());
return true;
}
private Intent createShareIntent()
{
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT,
"testing");
return shareIntent;
}
public void doShare(Intent shareIntent)
{
// When you want to share set the share intent.
myShareActionProvider.setShareIntent(shareIntent);
}
and this sdk version configuration:
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15"/>
But my problm is that I do not know how to call this. How do I actually get the menu to show up after the share button is clicked?
Thanks!
You can open an option menu from your code by calling openOptionsMenu()
method. From the doc here it does-
Programmatically opens the options menu. If the options menu is already open, this method does nothing.
But the question is why are you doing so. You have hardware menu button to open option menu. So it is better to leave that so. Even If you want to show user some option by button click then use Dialog. Why option menu?