I am trying to create a simple share menu which list down the various applications for sharing the text. I am following the same approach as android. This is my menuactivity
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.second, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection.
switch (item.getItemId()) {
case R.id.read_aloud_menu_item:
System.out.println("goes itno read aloud case");
System.out.println(item.getItemId());
mSpeech.speak(data, TextToSpeech.QUEUE_FLUSH, null);
//mSpeech.speak("Hello how are you", TextToSpeech.QUEUE_FLUSH, null);
mSpeech.setLanguage(Locale.US);
System.out.println(item.getItemId());
return true;
case R.id.share:
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
//sharejson(item.getItemId());
Intent in=new Intent(Intent.ACTION_SEND);
in.setAction(Intent.ACTION_SEND);
in.setType("text/plain");
in.putExtra(Intent.EXTRA_TEXT, "extra text that you want to put");
mShareActionProvider.setShareIntent(in);
//startActivity(Intent.createChooser(in, "Share via"));
return true;
}
}
My xml
<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/read_aloud_menu_item"
android:title="@string/read_aloud"
android:icon="@drawable/ic_reply_50" />
<item android:id="@+id/share"
android:title="@string/share"
android:icon="@drawable/ic_reply_50"
android:showAsAction="ifRoom"
android:actionProviderClass="android.widget.ShareActionProvider" />
</menu>
The share option gets displayed in the list, but nothing happens on clicking the menu option. I also tried the createchooser but that too in vain. The createChooser gives an error "No applications can perform this action"