开发者

Unique name of android phone

开发者 https://www.devze.com 2023-02-17 06:01 出处:网络
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(),

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

精彩评论

暂无评论...
验证码 换一张
取 消