如何获得唯一的设备 ID 在 Android 不能改变时,执行手机重置或操作系统更新?
更新: 19-11-2019
下面的答案与今天的情况无关。
So for any one looking for answers you should look at the documentation linked below
Https://developer.android.com/training/articles/user-data-ids
旧的回答 -现在不相关了。 你可以在下面的链接中查看这个博客
Http://android-developers.blogspot.in/2011/03/identifying-app-installations.html
ANDROID_ID
import android.provider.Settings.Secure; private String android_id = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
以上内容来自 link@是否有唯一的 Android 设备 ID?
更具体地说,是 Settings. Secure.ANDROID _ ID。这是一个64位的数量,在设备第一次引导时生成并存储。
ANDROID _ ID 似乎是唯一设备标识符 的不错选择。它也有缺点: 首先,在2.2之前的 Android 版本(“ Froyo”) ,它不是100% 可靠的。此外,在一个主要制造商的流行手机中,至少有一个被广泛观察到的 bug,其中每个实例都具有相同的 ANDROID _ ID。
下面的解决方案不是一个好的,因为 这个价值经得起设备擦除(“工厂重置”) ,因此,当你的一个客户擦除他们的设备并将其传递给另一个人时,你可能最终会犯一个严重的错误。
您可以使用下面的命令获得设备的 imei 号码
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.getDeviceId();
Http://developer.android.com/reference/android/telephony/telephonymanager.html#getdeviceid%28%29
添加这是清单
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
请阅读 Google 开发者博客上的这篇官方博文: Http://android-developers.blogspot.be/2011/03/identifying-app-installations.html
Conclusion For the vast majority of applications, the requirement is 来识别特定的设备,而不是物理设备。 幸运的是,这样做很简单。 有许多很好的理由可以避免尝试标识 对于那些想尝试的人来说,最好的方法是 可能在任何相当现代的东西上使用 ANDROID _ ID 遗留设备的一些备用启发式方法
Conclusion For the vast majority of applications, the requirement is 来识别特定的设备,而不是物理设备。 幸运的是,这样做很简单。
有许多很好的理由可以避免尝试标识 对于那些想尝试的人来说,最好的方法是 可能在任何相当现代的东西上使用 ANDROID _ ID 遗留设备的一些备用启发式方法
.
我使用以下代码来获得 Android ID。
String android_id = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID); Log.d("Android","Android ID : "+android_id);