Android中方法
public class UnityPlayerActivity extends Activity{@Override protected void onCreate (Bundle savedInstanceState){}//获取设备idpublic String OnGetDeviceID() {return SDKCommonHelper.OnGetDeviceID(this);}public static String getAndroidID(Activity cpGame) {String id = android.provider.Settings.Secure.getString(cpGame.getContentResolver(),android.provider.Settings.Secure.ANDROID_ID);return id == null ? "" : id;}//获取设备idpublic String GetDeviceId(Activity cpGame){String imei = null;if(cpGame==null){return imei;}if (ActivityCompat.checkSelfPermission(cpGame, "android.permission.READ_PHONE_STATE") == 0) {TelephonyManager tm = (TelephonyManager)cpGame.getSystemService("phone");imei = tm.getDeviceId();}if (imei == null) {imei = getAndroidID(cpGame);}if (imei == null) {imei = "";}CommonTools.LogPrint("======GetDeviceId==mDeviceId====="+imei);return imei;}}
OC中方法
/***获取广告码***/-(NSString *)getDeviceId{NSString *idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];return idfa;}#if defined(__cplusplus)extern "C"{#endifconst char* _iOS_GetSDKValue(const char* key){NSString* strFunc = [NSString stringWithUTF8String: key];NSLog(@"%@", [NSString stringWithFormat:@"ios sdk call _iOS_GetSDKValueFzl funcName : %@",strFunc]);if([strFunc isEqualToString:@"OnGetDeviceID"]){NSString* mDeviceIdstr = [[SDKCommonHelper shareSDKCommonHelper] getDeviceId];return strdup([mDeviceIdstr UTF8String]);}return 0;}#if defined(__cplusplus)}#endif
Unity中方法
/// <summary>/// 获取Android设备号/// </summary>/// <returns></returns>public static string GetDeviceID(){#if UNITY_ANDROIDAndroidJavaClass javaClass = newAndroidJavaClass("com.unity3d.player.UnityPlayer");AndroidJavaObject javaObject = javaClass.GetStatic<AndroidJavaObject>("currentActivity");return javaObject.Call<string>("OnGetDeviceID");#elif UNITY_IPHONEreturn Get("GetLogoByte")#endif}[DllImport("__Internal")]private static extern string _iOS_GetSDKValue(string key);public static string Get(string key){return _iOS_GetSDKValue(key);}