I'm using
final Intent notice = new Intent();
notice.setType("text/plain");
notice.putExtra(Intent.EXTRA_SUBJECT, "My Subject");
notice.putExtra(Intent.EXTRA_TEXT, "My Text");
try {
getContext().startActivity(Intent.createChooser(notice, "Send..."));
} catch(final android.content.ActivityNotFoundException ex) {
Toast.makeText(getContext(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
} catch(final SecurityException ex) {
Toast.makeText(getContext(), "Sorry, application does not have permissions to send to this destination.", Toast.LENGTH_SHORT).show();
} // try/catch
as indicated in How can I send emails from my Android application?
But, there are some applications, if chosen by the user, that will crash the application with a SecurityException
, as the current application does not have enough privileges to send the intend:
02-05 23:11:33.417: E/AndroidRuntime(20255): java.lang.SecurityException: Permission Denial: starting Intent { typ=text/plain flg=0x3000000 cmp=com.google.android.gm/.AutoSendActivity (has extras) } from ProcessRecord{4084ca60 20255:com.example.myapp/10065} (pid=20255, uid=10065) requires com.google.android.gm.permission.AUTO_SEND 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.os.Parcel.readException(Parcel.java:1322) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.os.Parcel.readException(Parcel.java:1276) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1351) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.app.Activity.startActivityForResult(Activity.java:2827) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.app.Activity.startActivity(Activity.java:2933) 02-05 23:11:33.417: E/AndroidRuntime(20255): at com.android.internal.app.ResolverActivity.onIntentSelected(ResolverActivity.java:203) 02-05 23:11:33.417: E/AndroidRuntime(20255): at com.android.internal.app.ResolverActivity.onClick(ResolverActivity.java:117) 02-05 23:11:33.417: E/AndroidRuntime(20255): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:873) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.widget.AdapterView.performItemClick(AdapterView.java:284) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.widget.ListView.performItemClick(ListView.java:3513) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.os.Handler.handleCallback(Handler.java:587) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.os.Handler.dispatchMessage(Handler.java:92) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.os.Looper.loop(Looper.java:130) 02-05 23:11:33.417: E/AndroidRuntime(20255): at android.app.ActivityThread.main(ActivityThread.java:3683) 02-05 23:11:33.417: E/AndroidRuntime(20255): at java.lang.reflect.Method.invokeNative(Native Method) 02-05 23:11:33.417: E/AndroidRuntime(20255): at java.lang.reflect.Method.invoke(Method.java:507) 02-05 23:11:33.417: E/AndroidRuntime(20255): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 02-05 23:11:33.417: E/AndroidRuntime(20255): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 02-05 23:11:33.417: E/AndroidRuntime(20255): at dalvik.system.NativeStart.main(Native Method)
As you can see, the exception is not touching any of my code directly. I don't want to add the missing permission to the manifest (I don't know which other applications will show up in the chooser), but simply handle the SecurityException
and notify the user. Where would I do so?
I'm on Android 2.3.6 in this case.
Thanks in advance!