Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by InvalidCola · Sep 03, 2013 at 10:22 AM · androidpluginunique-identifiers

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jix · Mar 03, 2014 at 01:06 AM 0
Share

Hello, did you find the solution? I'm stuck here.

avatar image InvalidCola · Mar 03, 2014 at 01:39 PM 0
Share

I added an answer which worked for me - hope it helps :)

2 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

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");
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jix · Mar 04, 2014 at 12:27 PM 0
Share

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?

avatar image InvalidCola · Mar 04, 2014 at 08:39 PM 0
Share

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

avatar image DevJeeth · Mar 25, 2019 at 01:48 PM 0
Share

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.

avatar image
-1

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!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image InvalidCola · Mar 04, 2014 at 08:42 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges