Android - Google+ share status fails

2019-04-10 23:37发布

问题:

I went over the Google's description on how to share status from my Android app to Google+: https://developers.google.com/+/mobile/android/share/
(I'm doing an example app that does exactly what they do in the example)

I'm getting this exception:

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)

It's seems that the error is coming from within "Google Play Services" but I don't know why?

Ideas?

回答1:

I see this same error using google-play-services 6.1.71. Edu Barbas above has the correct answer, using ShareCompat.IntentBuilder seems to resolve the issue. I don't have enough points to comment on his answer, but I wanted to add that the building of the intent and starting of the share activity is a little different:

      Intent shareIntent = ShareCompat.IntentBuilder.from(TheCurrentActivity.this)
                .setType("text/plain")
                .setText(statusMessage)
                .getIntent()
                .setPackage("com.google.android.apps.plus");

        startActivityForResult(shareIntent, 0);

Leaving off the setPackage("com.google.android.apps.plus") line brings up a general android share dialog, allowing you to share via email, bluetooth, and sms, in addition to google plus. Adding the setPackage line allows you to bypass that dialog and share exclusively through google plus.



回答2:

I experienced the same behavior after we updated the Google Play Services library in my project. I launched the G+ share dialog via PlusShare.Builder, which made the app crash. I solved the issue by switching to ShareCompat.IntentBuilder instead (the share dialog is exactly the same).