我查看了 Google 关于如何将 Android 应用程序的状态共享到 Google+ 的说明:https://developers.google.com/+/mobile/android/share/ https://developers.google.com/+/mobile/android/share/
(我正在做一个示例应用程序,它的功能与示例中的操作完全相同)
我收到这个异常:
Process: com.google.android.gms.ui, PID: 19643
java.lang.IllegalArgumentException
at com.google.k.a.aj.a(SourceFile:72)
at com.google.android.gms.plus.audience.a.e.<init>(SourceFile:63)
at com.google.android.gms.plus.audience.a.e.<init>(SourceFile:53)
at com.google.android.gms.plus.audience.a.d.<init>(SourceFile:28)
at com.google.android.gms.plus.sharebox.al.a(SourceFile:213)
at android.support.v4.app.ax.c(SourceFile:490)
at android.support.v4.app.ax.d(SourceFile:499)
at android.support.v4.app.ax.b(SourceFile:646)
at com.google.android.gms.plus.sharebox.al.a(SourceFile:192)
at com.google.android.gms.plus.sharebox.ShareBoxActivity.a(SourceFile:525)
at com.google.android.gms.plus.sharebox.au.a(SourceFile:810)
at com.google.android.gms.plus.internal.ce.a(SourceFile:214)
at com.google.android.gms.common.internal.v.d(SourceFile:200)
at com.google.android.gms.common.internal.u.handleMessage(SourceFile:136)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
该错误似乎来自“Google Play 服务”内部,但我不知道为什么?
Ideas?
我使用 google-play-services 6.1.71 看到同样的错误。上面的 Edu Barbas 有正确的答案,使用 ShareCompat.IntentBuilder 似乎可以解决该问题。我没有足够的观点来评论他的回答,但我想补充一点,意图的构建和共享活动的启动有点不同:
Intent shareIntent = ShareCompat.IntentBuilder.from(TheCurrentActivity.this)
.setType("text/plain")
.setText(statusMessage)
.getIntent()
.setPackage("com.google.android.apps.plus");
startActivityForResult(shareIntent, 0);
去掉 setPackage("com.google.android.apps.plus") 行会弹出一个通用的 Android 共享对话框,除了 google plus 之外,还允许您通过电子邮件、蓝牙和短信进行共享。添加 setPackage 行可以让您绕过该对话框并通过 google plus 独家共享。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)