Skip to main content
  1. About
  2. For Teams
Asked
Viewed 713 times
Part of Mobile Development Collective
2

I want to get a unique name or id of the android phone by using the following :

String uniqueID = android.provider.Settings.Secure.getString(getContentResolver(),
    android.provider.Settings.Secure.ANDROID_ID); 

but it is return null , i do not know what is the problem .
Any help?

2 Answers 2

1

Personally, I wouldn't use ANDROID_ID. It's been known to be null sometimes and it can change after a factory reset. The device id on the other hand is always non-null (in my experience at least), and unique.

You can add this code to your Activity to retrieve the unique device id of the phone:

TelephonyManager tm =
  (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);

String device = tm.getDeviceId();
Sign up to request clarification or add additional context in comments.

2 Comments

That will also require the READ_PHONE_STATE permission. developer.android.com/reference/android/…
Keep in mind that this won't work on a phone without a radio, like a WiFi-only tablet.
0

Try it with context,

String m_androidId = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.