gpt4 book ai didi

c# - 如何检测是否从 Unity 安装了 Google Play 服务?

转载 作者:行者123 更新时间:2023-12-05 00:14:22 26 4
gpt4 key购买 nike

有些设备没有安装 Google Play 服务,所以我无法使用 Google Play 游戏服务等 API。在 Unity 中,我如何检测到未安装 Play 服务,因此我必须跳过调用 GPGS?

我知道我需要调用 GoogleApiAvailability.isGooglePlayServicesAvailable ,但我需要从 C# 开始。

最佳答案

您需要使用 Unity 中的 JNI 支持才能从 C# 调用 Java API。在这种情况下,对 isGooglePlayServicesAvailable 的调用如下所示:

 public 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);

// 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;
}

关于c# - 如何检测是否从 Unity 安装了 Google Play 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32721499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com