Fix crash on opening a URL on Android.

This commit is contained in:
2023-07-04 11:13:28 +08:00
parent f65e4f1900
commit 7fce9591a9

View File

@@ -4,7 +4,11 @@ namespace Cryville.Common.Unity {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
System.Diagnostics.Process.Start(url);
#elif UNITY_ANDROID
new UnityEngine.AndroidJavaClass("world.cryville.common.unity.UrlOpener").CallStatic("open", new object[] { url });
UnityEngine.AndroidJNI.AttachCurrentThread();
using (var clazz = new UnityEngine.AndroidJavaClass("world.cryville.common.unity.UrlOpener")) {
clazz.CallStatic("open", url);
}
UnityEngine.AndroidJNI.DetachCurrentThread();
#else
#error Unknown platform.
#endif