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 UnityEngine;
@ -34,23 +35,29 @@ namespace Guru
private static void GetIOSDeviceInfo()
{
#if UNITY_IOS
string content = iOSDeviceInfo();
Debug.Log($"GetDeviceInfo:{content}");
if(!string.IsNullOrEmpty(content))
try
{
string[] infos = content.Split('$');
IPMConfig.SetDeviceId(infos[0]);
IPMConfig.IPM_APP_VERSION = infos[1];
IPMConfig.IPM_TIMEZONE = infos[2];
IPMConfig.IPM_MODEL = infos[3];
IPMConfig.IPM_LANGUAGE = infos[4];
IPMConfig.IPM_LOCALE = infos[5];
IPMConfig.IPM_COUNTRY_CODE = infos[6];
IsGetDeviceInfoSuccess = true;
Debug.Log($"[SDK] --- GetIOSDeviceInfo:: iOSDeviceInfo<string>");
string content = iOSDeviceInfo();
Debug.Log($"GetDeviceInfo:{content}");
if(!string.IsNullOrEmpty(content))
{
string[] infos = content.Split('$');
IPMConfig.SetDeviceId(infos[0]);
IPMConfig.IPM_APP_VERSION = infos[1];
IPMConfig.IPM_TIMEZONE = infos[2];
IPMConfig.IPM_MODEL = infos[3];
IPMConfig.IPM_LANGUAGE = infos[4];
IPMConfig.IPM_LOCALE = infos[5];
IPMConfig.IPM_COUNTRY_CODE = infos[6];
IsGetDeviceInfoSuccess = true;
}
}
catch (Exception ex)
{
Debug.LogError(ex);
}
#endif
}
public static void SetiOSBadge()
@ -82,23 +89,31 @@ namespace Guru
private static void GetAndroidDeviceInfo()
{
#if UNITY_ANDROID
_androidJavaObject ??= new AndroidJavaObject("com.guru.u3d2android.u3d2android");
if (_androidJavaObject != null)
{
string content = _androidJavaObject.Call<string>("getDeviceInfo");
Debug.Log($"GetDeviceInfo:{content}");
if(!string.IsNullOrEmpty(content))
{
string[] infos = content.Split('$');
IPMConfig.IPM_BRAND = infos[0];
IPMConfig.IPM_LANGUAGE = infos[1];
IPMConfig.IPM_MODEL = infos[2];
IPMConfig.IPM_TIMEZONE = infos[4];
IPMConfig.IPM_LOCALE = infos[5];
IPMConfig.IPM_COUNTRY_CODE = infos[6];
IsGetDeviceInfoSuccess = true;
}
}
try
{
_androidJavaObject ??= new AndroidJavaObject("com.guru.u3d2android.u3d2android");
if (_androidJavaObject != null)
{
Debug.Log($"[SDK] --- GetAndroidDeviceInfo:: com.guru.u3d2android.u3d2android: getDeviceInfo<string>");
string content = _androidJavaObject.Call<string>("getDeviceInfo");
Debug.Log($"GetDeviceInfo:{content}");
if(!string.IsNullOrEmpty(content))
{
string[] infos = content.Split('$');
IPMConfig.IPM_BRAND = infos[0];
IPMConfig.IPM_LANGUAGE = infos[1];
IPMConfig.IPM_MODEL = infos[2];
IPMConfig.IPM_TIMEZONE = infos[4];
IPMConfig.IPM_LOCALE = infos[5];
IPMConfig.IPM_COUNTRY_CODE = infos[6];
IsGetDeviceInfoSuccess = true;
}
}
}
catch (Exception ex)
{
Debug.LogError(ex);
}
#endif
}