Hi everyone!
I tried looking for a similar question/answer, but I cannot seem to find anything concrete.
Is it possible to get the Android device ID in Unity without using a .jar plugin? Do you need a .jar file to use AndroidJNI, or can you just call Secure.ANDROID_ID using AndroidJNI.CallStringMethod or something like that, directly from Unity?!
NOTE: I don’t think I can use SystemInfo.deviceUniqueIdentifier, since it doesn’t exactly return the AndroidID (which is what I need) - or am I wrong about that?
Best,
Simon
This code should get the Android ID:
AndroidJavaClass up = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = up.GetStatic<AndroidJavaObject> ("currentActivity");
AndroidJavaObject contentResolver = currentActivity.Call<AndroidJavaObject> ("getContentResolver");
AndroidJavaClass secure = new AndroidJavaClass ("android.provider.Settings$Secure");
string android_id = secure.CallStatic<string> ("getString", contentResolver, "android_id");
How can I find the IMEI with this method?
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String IMEI = tm.getDeviceId();
How can i fix this with this method?
Thank you!