playgameservices / android-basic-samples

Google Play game services - Android samples
Apache License 2.0
971 stars 973 forks source link

App Crashing When Viewing Leaderboard (No Activity found to handle Intent) #243

Closed hed5meg closed 6 years ago

hed5meg commented 7 years ago

I am running into an edge case when attempting to display leaderboards in my game (it must work at least 99% of the time). In my developer console there is a report of an App Crash because it cannot find the VIEW_LEADERBOARD_SCORES intent (stack trace below). I am able to reproduce this on my Nexus 6P by disabling the Google Play Game App. I added the following code before I do any leadboard related activity, but it always returns success (probably because Google Play Services are available, but it doesn't check for the case where the Google Play Game App has been disabled). How can I explicitly check that that app is disabled, or catch the exception in Unity so that the app doesn't crash. I am usuing Unity 5.5.1.p2 and GPGS Plugin 0.9.36. All of this happens after a successful logon. I can publish scores successfully as well.

public bool IsPlayServicesAvailable() { const string GoogleApiAvailability_Classname = "com.google.android.gms.common.GoogleApiAvailability"; AndroidJavaClass clazz = new AndroidJavaClass(GoogleApiAvailability_Classname); AndroidJavaObject obj = clazz.CallStatic("getInstance");

var androidJC = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var activity = androidJC.GetStatic<AndroidJavaObject>("currentActivity");

int value = obj.Call<int>("isGooglePlayServicesAvailable", activity);

// result codes from https://developers.google.com/android/reference/com/google/android/gms/common/ConnectionResult

// 0 == success
// 1 == service_missing
// 2 == update service required
// 3 == service disabled
// 18 == service updating
// 9 == service invalid
return value == 0;

} java.lang.Error: FATAL EXCEPTION [main] Unity version : 5.5.2f1 Device model : samsung SM-G920V Device fingerprint: Verizon/zerofltevzw/zerofltevzw:6.0.1/MMB29K/G920VVRS4CQA3:user/release-keys Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{net.fowers.turning/com.google.games.bridge.NativeBridgeActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.android.gms.games.VIEW_LEADERBOARD_SCORES dat=version:9452000 flg=0x4000000 pkg=com.google.android.play.games (has extras) } at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) at android.app.ActivityThread.access$1100(ActivityThread.java:222) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) 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) Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.android.gms.games.VIEW_LEADERBOARD_SCORES dat=version:9452000 flg=0x4000000 pkg=com.google.android.play.games (has extras) } at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1878) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1545) at android.app.Activity.startActivityForResult(Activity.java:4283) at android.app.Activity.startActivityForResult(Activity.java:4230) at com.google.games.bridge.NativeBridgeActivity.startActivityForResult(NativeBridgeActivity.java:86) at com.google.games.bridge.NativeBridgeActivity.onStart(NativeBridgeActivity.java:62) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1265) at android.app.Activity.performStart(Activity.java:6915) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3217) ... 9 more

mwgray commented 6 years ago

Disabling Google Play Games resulted in a 12501 error with the Type A Number sample. You should be able to catch this as an APIException. See the handler in onActivityResult.

If you are still encountering this issue and since this is a Unity question, I suggest creating an issue the Google Play Games plugin for Unity project.