Chcę zaimplementować akcję akcji w moim projekcie, ale kiedy użyłem MenuItem
, to daje to błąd Runtime, aby zamiast tego używać MenuItemCompat
, ale też zbyt dawał błąd.Jak zaimplementować akcję udostępniania w systemie Android?
Oto mój kod:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_third_, menu);
MenuItem menuItem = menu.findItem(R.id.menu_item_share);
mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider();
mShareActionProvider.setShareIntent(getDefaultShareIntent());
return true;
}
public Intent getDefaultShareIntent(){
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "SUBJECT");
shareIntent.putExtra(Intent.EXTRA_TEXT,"Extra Text");
return shareIntent;
}
Należy dodać StackTrace również. – tynn