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 はありますか?