- Home /
Getting Android ID in Unity
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
I added an answer which worked for me - hope it helps :)
Answer by InvalidCola · Mar 03, 2014 at 01:37 PM
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");
Thanks for the code, but there is one thing I need to mention about this code. The value of android_id doesn't match the aid I find when I dial ##8255## on my phone.
I'm new to this android device id thing, isn't the aid is the android device?
Hm.. Try an app like this: https://play.google.com/store/apps/details?id=com.evozi.deviceid&hl=da -- it should give you the Android ID so you can compare. $$anonymous$$y tests with the code above give me the correct android ID. Of course the code will only work when it runs on your android device.
Here's some info on the id you get when dialing ##8255## : http://stackoverflow.com/questions/16560666/how-can-i-get-the-android-device-id-which-i-get-on-dialing-8255
I'm not sure what you need the ID for? The Android ID I am using is good as a unique identifier for the user, as you can see here: http://developer.android.com/reference/android/provider/Settings.Secure.html
Using the Device ID app to verify after fetching it from current code, does not match. Could you help me out here. What could be the problem? I Did the exact same thing and display it on the UI when launched, but the ID I get is totally different.
Answer by trickyjohn · Mar 04, 2014 at 02:42 PM
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!
What you posted is not an answer (you should post it as a comment ins$$anonymous$$d).
I'm not sure if you can use this method to get the I$$anonymous$$EI - I'm really not an expert on Android workings (I got some help with the solution that I found). Sorry :(
Your answer
Follow this Question
Related Questions
iPhone Unique Identifier 1 Answer
android plugin for script.enabled 2 Answers
How to alter the Android Manifest to use my ad-displaying activity in Unity? 0 Answers
Update Notification 1 Answer
Communicate with Android native plugin 0 Answers