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.pro开发者_如何学Cvider.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?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();
Try it with context,
String m_androidId = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
精彩评论