OAID调用接口修改测试
parent
0b2891c4dc
commit
853680239d
|
|
@ -7,6 +7,23 @@ public class DeviceIdHandle : MonoBehaviour
|
|||
private static DeviceIdHandle _instance;
|
||||
private AndroidJavaObject oaidActivity;
|
||||
|
||||
class OaidCallbackProxy : AndroidJavaProxy
|
||||
{
|
||||
public OaidCallbackProxy() : base("com.example.oaidtest2.DemoHelper$OaidCallback") { }
|
||||
|
||||
void onResult(int code, string msg, string oaid, long durationMs)
|
||||
{
|
||||
if (code == 0)
|
||||
{
|
||||
Debug.Log($"OAID: {oaid} (耗时: {durationMs}ms)");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"OAID 获取失败: {msg}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DeviceIdHandle Instance
|
||||
{
|
||||
get
|
||||
|
|
@ -112,4 +129,17 @@ public class DeviceIdHandle : MonoBehaviour
|
|||
{
|
||||
Debug.Log("Received IMEI: " + imei);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
||||
var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
|
||||
var appContext = activity.Call<AndroidJavaObject>("getApplicationContext");
|
||||
|
||||
var helperClass = new AndroidJavaClass("com.example.oaidtest2.DemoHelper");
|
||||
var helper = helperClass.CallStatic<AndroidJavaObject>("getInstance", appContext);
|
||||
|
||||
helper.Call("getOAID", new OaidCallbackProxy());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,4 @@
|
|||
android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
tools:replace="android:allowBackup" >
|
||||
<activity android:name="com.example.oaidtest2.OAID_Activity" >
|
||||
<meta-data
|
||||
android:name="unityplayer.UnityActivity"
|
||||
android:value="true" />
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
Binary file not shown.
Loading…
Reference in New Issue