[英]Unique ID for Android device
我需要每個設備唯一的ID。 該ID將存儲在服務器中,並將用於標識設備。 我正在考慮使用IMEI號碼,但出於隱私原因,我不想將IMEI號碼發送到服務器。
所以,我正在考慮這樣做
- 獲取IMEI號碼。
- 使用SHA-1哈希IMEI號。
- 發送到服務器
這是獲取唯一設備ID而不擔心隱私的可靠方法嗎? 請指教。
使用以下方法獲取IMEI號碼
String identifier = null;
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if (tm != null)
identifier = tm.getDeviceId();
if (identifier == null || identifier .length() == 0)
identifier = Secure.getString(activity.getContentResolver(),Secure.ANDROID_ID);
並添加此權限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
您可以使用ANDROID_ID,但在某些設備中,這是一個錯誤,並且似乎返回了相同的ID。 檢查參考是否有相同的https://groups.google.com/forum/#!topic/android-developers/U4mOUI-rRPY 。 作為后備,我執行以下操作:
String deviceId = Secure.getString(ActivationActivity.this.getContentResolver(), Secure.ANDROID_ID);
if ("9774d56d682e549c".equals(deviceId)) {
deviceId= UUID.randomUUID().toString();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.