我认为比较好的有2个:1个是ANDROID_ID(与系统有关,刷系统后变成新值),第二个是UUID(与设备,时间有关)
ANDROID_ID获取方法:
//在模拟器上获取是NULL,但是在真机上可以获取到,只要系统不变,每次获取值都一样
import android.provider.Settings.Secure;
String android_id=Secure.getString(Activity.getContentResolver(), Secure.ANDROID_ID);
UUID获取方法:
final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.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());
String uniqueId = deviceUuid.toString();
最后的deviceID可能是这样的结果: 00000000-54b3-e7c7-0000-000046bffd97
ANDROID_ID获取方法:
//在模拟器上获取是NULL,但是在真机上可以获取到,只要系统不变,每次获取值都一样
import android.provider.Settings.Secure;
String android_id=Secure.getString(Activity.getContentResolver(), Secure.ANDROID_ID);
UUID获取方法:
final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.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());
String uniqueId = deviceUuid.toString();
最后的deviceID可能是这样的结果: 00000000-54b3-e7c7-0000-000046bffd97