2013-07-03 67 views
1

我需要一個對每個設備都是唯一的ID。該ID將存儲在服務器中,並將用於識別設備。我正在考慮使用IMEI號碼,但我不希望將IMEI號碼發送到服務器以保護隱私。Android設備的唯一ID

所以,我想這樣做

  1. 獲取IMEI號碼。
  2. 使用SHA-1散列IMEI號碼。
  3. 發送給服務器

這是獲得唯一的設備ID沒有隱私問題的一種可靠的方法?請指教。

回答

0

你可以使用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(); 
             } 
1

獲取使用以下

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

IMEI號並添加此權限:

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