4
要獲取Android手機/平板電腦的唯一的設備ID,我們使用以下命令:如何獲得唯一的設備ID爲亞馬遜Kindle Fire
((TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId()
但是對於Kindle Fire的,我們不能得到一個。
任何想法?
要獲取Android手機/平板電腦的唯一的設備ID,我們使用以下命令:如何獲得唯一的設備ID爲亞馬遜Kindle Fire
((TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId()
但是對於Kindle Fire的,我們不能得到一個。
任何想法?
你應該嘗試使用以下行:
deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
這將讓來自平板電腦的設備ID,你只使用代碼工作在手機上(它將返回null
在平板電腦上)
把
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
然後
試試這個:
public String deviceId;
則:
// ------------- get UNIQUE device ID
deviceId = String.valueOf(System.currentTimeMillis()); // --------
// backup for
// tablets etc
try {
final TelephonyManager tm = (TelephonyManager) getBaseContext()
.getSystemService(Main.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, tmPhone, androidId;
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId = ""
+ android.provider.Settings.Secure.getString(
getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(),
((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
deviceId = deviceUuid.toString();
} catch (Exception e) {
Log.v("Attention", "Nu am putut sa iau deviceid-ul !?");
}
// ------------- END get UNIQUE device ID
從這裏開始 - >Is there a unique Android device ID?