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?

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
M7M
  • 11,791
  • 3
  • 13
  • 4

2 Answers2

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();
dbyrne
  • 52,081
  • 13
  • 82
  • 102
  • That will also require the READ_PHONE_STATE permission. http://developer.android.com/reference/android/Manifest.permission.html#READ_PHONE_STATE – Robby Pond Mar 14 '11 at 19:19
  • Keep in mind that this won't work on a phone without a radio, like a WiFi-only tablet. – EboMike Mar 14 '11 at 21:23
0

Try it with context,

String m_androidId = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
SARATH V
  • 449
  • 6
  • 25