M7M
M7M

Reputation: 13071

Unique name of android phone

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?

Upvotes: 2

Views: 697

Answers (2)

SARATH V
SARATH V

Reputation: 500

Try it with context,

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

Upvotes: 0

dbyrne
dbyrne

Reputation: 61081

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();

Upvotes: 1

Related Questions