获取 Android 设备的唯一 ID?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24262851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:56:47  来源:igfitidea点击:

Get Unique ID of Android Device?

android

提问by user3736827

I have htc one b model android phone. I want to know my device ID. I do not know how could I finding out my device ID .

我有 HTC One b 型号的安卓手机。我想知道我的设备 ID。我不知道如何找到我的设备 ID。

回答by Siddharth_Vyas

Try this :

尝试这个 :

    String deviceId = Secure.getString(this.getContentResolver(),
            Secure.ANDROID_ID);
    Toast.makeText(this, deviceId, Toast.LENGTH_SHORT).show();

android.provider.Settings.Secure.ANDROID_ID

android.provider.Settings.Secure.ANDROID_ID

A 64-bit number (as a hex string) that is randomly generated on the device's first boot and should remain constant for the lifetime of the device.

在设备第一次启动时随机生成的 64 位数字(作为十六进制字符串)应在设备的生命周期内保持不变。

Source Link : http://blog.vogella.com/2011/04/11/android-unique-identifier/

来源链接:http: //blog.vogella.com/2011/04/11/android-unique-identifier/

Note: The value may change if a factory reset is performed on the device.

注意如果在设备上执行恢复出厂设置,该值可能会发生变化。

回答by Y.S

Try this:

尝试这个:

TelephonyManager TM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

// IMEI No.
String imeiNo = TM.getDeviceId();

// IMSI No.
String imsiNo = TM.getSubscriberId();

// SIM Serial No.
String simSerialNo  = TM.getSimSerialNumber();

// Android Unique ID
String androidId = Settings.Secure.getString(this.getContentResolver(),Settings.Secure.ANDROID_ID);

Don't forget to add

不要忘记添加

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

to your manifest file.

到您的清单文件。

回答by dileep

Try this:

尝试这个:

Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);