I use
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(); }
as indicated in How to send email from an Android app?
But there are some applications if they are selected by the user, which will lead to the failure of the application using SecurityException , since the current application does not have sufficient privileges to send the intent:
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∗87)
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.javahaps683)
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∗97)
02-05 23: 11: 33.417: E / AndroidRuntime (20255): at dalvik.system.NativeStart.main (Native Method)
As you can see, the exception does not apply directly to my code. I don’t want to add the missing manifest permission (I don’t know what other applications will be displayed in the selection element), but just handle a SecurityException and notify the user. Where can i do this?
In this case, I'm on Android 2.3.6.
Thanks in advance!
source share