要获取 Android 手机/平板电脑上的唯一设备 ID,我们使用以下方法:
((TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId()
但是对于 Kindle Fire,我们买不到。
有任何想法吗?
要获取 Android 手机/平板电脑上的唯一设备 ID,我们使用以下方法:
((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
从这里 ->是否有唯一的 Android 设备 ID?