update: 添加 Android 设备获取信息 TryCatch 块

Signed-off-by: huyufei <yufei.hu@castbox.fm>
deeplink
胡宇飞 2024-05-22 12:33:49 +08:00
parent 7867db4655
commit e2c3b5bc7c
1 changed files with 46 additions and 31 deletions

View File

@ -1,3 +1,4 @@
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using UnityEngine; using UnityEngine;
@ -34,6 +35,9 @@ namespace Guru
private static void GetIOSDeviceInfo() private static void GetIOSDeviceInfo()
{ {
#if UNITY_IOS #if UNITY_IOS
try
{
Debug.Log($"[SDK] --- GetIOSDeviceInfo:: iOSDeviceInfo<string>");
string content = iOSDeviceInfo(); string content = iOSDeviceInfo();
Debug.Log($"GetDeviceInfo:{content}"); Debug.Log($"GetDeviceInfo:{content}");
if(!string.IsNullOrEmpty(content)) if(!string.IsNullOrEmpty(content))
@ -48,9 +52,12 @@ namespace Guru
IPMConfig.IPM_COUNTRY_CODE = infos[6]; IPMConfig.IPM_COUNTRY_CODE = infos[6];
IsGetDeviceInfoSuccess = true; IsGetDeviceInfoSuccess = true;
} }
}
catch (Exception ex)
{
Debug.LogError(ex);
}
#endif #endif
} }
public static void SetiOSBadge() public static void SetiOSBadge()
@ -82,9 +89,12 @@ namespace Guru
private static void GetAndroidDeviceInfo() private static void GetAndroidDeviceInfo()
{ {
#if UNITY_ANDROID #if UNITY_ANDROID
try
{
_androidJavaObject ??= new AndroidJavaObject("com.guru.u3d2android.u3d2android"); _androidJavaObject ??= new AndroidJavaObject("com.guru.u3d2android.u3d2android");
if (_androidJavaObject != null) if (_androidJavaObject != null)
{ {
Debug.Log($"[SDK] --- GetAndroidDeviceInfo:: com.guru.u3d2android.u3d2android: getDeviceInfo<string>");
string content = _androidJavaObject.Call<string>("getDeviceInfo"); string content = _androidJavaObject.Call<string>("getDeviceInfo");
Debug.Log($"GetDeviceInfo:{content}"); Debug.Log($"GetDeviceInfo:{content}");
if(!string.IsNullOrEmpty(content)) if(!string.IsNullOrEmpty(content))
@ -99,6 +109,11 @@ namespace Guru
IsGetDeviceInfoSuccess = true; IsGetDeviceInfoSuccess = true;
} }
} }
}
catch (Exception ex)
{
Debug.LogError(ex);
}
#endif #endif
} }