public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item =menu.findItem(R.id.action_settings);
shareActionProvider=(ShareActionProvider) MenuItemCompat.getActionProvider(item);
/* shareActionProvider=(ShareActionProvider) item.getActionProvider();*/
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "aa");
shareActionProvider.setShareIntent(intent);
return true;
}
return super.onOptionsItemSelected(item);
}