Reputation:
I tried to share some text with gmail in my app :
String shareBody = "bla bla bla";
Intent sharingIntent = new Intent(Intent.ACTION_VIEW);
sharingIntent.setType("plain/text");
sharingIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "bla bla bla");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(sharingIntent);
But I have the error message when I click on the share button :
FATAL EXCEPTION: main
Process: opteamit.com.belami, PID: 14263
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW typ=plain/text cmp=com.google.android.gm/.ComposeActivityGmail (has extras) } from ProcessRecord{f3970e9 14263:opteamit.com.belami/u0a170} (pid=14263, uid=10170) not exported from uid 10085
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3131)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1541)
at android.app.Activity.startActivityForResult(Activity.java:4298)
at android.app.Activity.startActivityForResult(Activity.java:4245)
at android.app.Activity.startActivity(Activity.java:4582)
at android.app.Activity.startActivity(Activity.java:4550)
at opteamit.com.belami.AideActivity$4$1.onSuccess(AideActivity.java:89)
at com.loopj.android.http.JsonHttpResponseHandler$1$1.run(JsonHttpResponseHandler.java:152)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
What can I do ?
Upvotes: 4
Views: 1675
Reputation: 1007296
What can I do ?
Get rid of the setClassName()
call.
First, that activity is not exported, so you cannot invoke it directly.
Second, that activity may not exist in past, present, and future editions of Gmail.
Third, not every Android user uses Gmail. Share where the user wants.
Upvotes: 3