Unity 中检测Google Play 服务是否可用

问题回答链接:https://github.com/playgameservices/play-games-plugin-for-unity/issues/715

 

 

    public static bool IsPlayServicesAvailable()
    {
        const string GoogleApiAvailability_Classname = "com.google.android.gms.common.GoogleApiAvailability";
        AndroidJavaClass clazz = new AndroidJavaClass(GoogleApiAvailability_Classname);
        AndroidJavaObject obj = clazz.CallStatic<AndroidJavaObject>("getInstance");
        var androidJC = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        var activity = androidJC.GetStatic<AndroidJavaObject>("currentActivity");
        int value = obj.Call<int>("isGooglePlayServicesAvailable", activity);
        // 0 == success
        // 1 == service_missing
        // 2 == update service required
        // 3 == service disabled
        // 18 == service updating
        // 9 == service invalid
        Debug.Log("GALogController Log IsPlayServicesAvailable value:" + value);
        return value == 0;
    }

 

posted @ 2021-03-30 15:17  三里路异乡客  阅读(382)  评论(0编辑  收藏  举报