I am using shareactionprovider to share the text but cannot get it to work.The same code works fine with the menu option. When I share text using shareactionprovider text is not shared but when I share same text using menu share option text gets shared.
sorry for my poor english
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getActionBar().setDisplayHomeAsUpEnabled(true);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.share2, menu);
menu.add(Menu.NONE, MENU_ITEM1, Menu.NONE, "Share");
MenuItem mShareActionProviderItem = (MenuItem) menu.findItem(R.id.menu_share2);
mShareActionProvider = (ShareActionProvider) mShareActionProviderItem.getActionProvider();
Intent t = new Intent(Intent.ACTION_SEND);
t.setAction(Intent.ACTION_SEND);
t.setType("text/plain");
CharSequence displayContents = contentsTextView.getText().toString();
t.putExtra(Intent.EXTRA_TEXT,displayContents);
mShareActionProvider.setShareIntent(t);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_ITEM1:
Intent shareIntent2 = new Intent();
shareIntent2.setAction(Intent.ACTION_SEND);
shareIntent2.setType("text/plain");
CharSequence displayContents2 = contentsTextView.getText().toString();
shareIntent2.putExtra(Intent.EXTRA_TEXT,displayContents2);
startActivity(shareIntent2);
break;
}
return super.onOptionsItemSelected(item);
}
contentsTextView
is probably empty whenonCreateOptionsMenu()
is called.Instead, update the
Intent
as the user types:(as seen in this sample project)