我正在开发 android 项目,其中激活过程是针对设备ID 完成的。所以我必须为每个设备生成一个唯一的ID。我通过网上冲浪有两种方式。
在这种情况下,我会生成如下ID。
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uid = tManager.getDeviceId();
但它为模拟器提供了“0”的组合以及实际设备的唯一值。
第二种方式如下
String android_id = Secure.getString(Main.this.getContentResolver(),Secure.ANDROID_ID);
即使对于模拟器,这也给出了唯一值。那么这两个ID之间有什么不同呢。哪一个更符合我的要求。
答案 0 :(得分:2)
生成设备ID实际上并不像看起来那么简单,因为结果可能会因Android版本,制造商等而异。
查看这篇很棒的帖子,解释了生成设备ID的每种方法的优缺点: http://developer.samsung.com/android/technical-docs/How-to-retrieve-the-Device-Unique-ID-from-android-device
答案 1 :(得分:1)
这个会给你唯一的设备ID,你可以去找它
import android.provider.Settings.Secure;
String android_id = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);
*请注意,这将在出厂重置时更改,请自行承担风险! 或者可以在root手机上更改!
,此article会为您提供所有可以从deivce中检索的唯一信息,例如..
答案 2 :(得分:0)
String android_id = Secure.getString(Main.this.getContentResolver(),Secure.ANDROID_ID);
给出在设备首次启动时随机生成的64位数字(作为十六进制字符串),并且应在设备的生命周期内保持不变(如果在设备上执行恢复出厂设置,则该值可能会更改。)ANDROID_ID对于唯一的设备标识符来说似乎是个不错的选择。
,而
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uid = tManager.getDeviceId();
给出了手机的IMEI,MEID,ESN和IMSI,这是该硬件的独特之处,在整个设备的使用寿命期间是不变的。