Rah*_*rma 16 android tablet-pc
我想获得每个Android设备唯一的设备ID.我目前正在开发平板电脑设备.想获得唯一的设备ID并存储相应的值...
所以,我想知道如果我使用TelephonyManager.getDeviceId()......,平板电脑设备是否会返回一个值?或者是否有任何其他值对每个设备唯一?
Jor*_*sys 59
TelephonyManger.getDeviceId()返回唯一的设备ID,例如,GSM的IMEI和CDMA电话的MEID或ESN.
final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String myAndroidDeviceId = mTelephony.getDeviceId();
Run Code Online (Sandbox Code Playgroud)
但我建议使用:
Settings.Secure.ANDROID_ID,它将Android ID作为唯一的64位十六进制字符串返回.
String myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
Run Code Online (Sandbox Code Playgroud)
有时TelephonyManger.getDeviceId()将返回null,因此为了确保您将使用此方法的唯一ID:
public String getUniqueID(){
String myAndroidDeviceId = "";
TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null){
myAndroidDeviceId = mTelephony.getDeviceId();
}else{
myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
}
return myAndroidDeviceId;
}
Run Code Online (Sandbox Code Playgroud)
这不是一个重复的问题.事实证明,Google的CTS要求TelephonyManager的getPhoneType需要为none,而对于非电话设备,TelephonyManager的getDeviceId需要为null.
所以要获得IMEI,请尝试使用:
String imei = SystemProperties.get("ro.gsm.imei")
Run Code Online (Sandbox Code Playgroud)
不幸的是,SystemProperties是Android操作系统中的非公共类,这意味着常规应用程序无法公开使用它.尝试查看这篇文章以获取访问权限:android.os.SystemProperties在哪里
| 归档时间: |
|
| 查看次数: |
27738 次 |
| 最近记录: |