我尝试在我的应用中与gmail分享一些文字:
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);
但是当我点击分享按钮时出现错误消息:
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)
我该怎么办?
答案 0 :(得分:3)
我该怎么办?
摆脱setClassName()
电话。
首先,该活动未导出,因此您无法直接调用它。
其次,该活动可能不存在于Gmail的过去,现在和将来版本中。
第三,并非每个Android用户都使用Gmail。 Share where the user wants。