0

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!

Genadinik
  • 18,153
  • 63
  • 185
  • 284
  • I am not sure what is your problem here, you want to display a menu item when this share button is clicked? Why do you have both a share button and a share menu item? – Yoann Hercouet Apr 20 '13 at 03:48
  • @YoannHercouet the reason I have a share button is so I can put it within the content of the screen. But I am not sure how to display the menu of possible social networks and emails with which the content can be shared. – Genadinik Apr 20 '13 at 11:44

1 Answers1

1

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?

stinepike
  • 54,068
  • 14
  • 92
  • 112