gpt4 book ai didi

android - TelephonyManger.getDeviceId() 是否会为 Galaxy Tab 等平板电脑返回设备 ID ...?

转载 作者:IT老高 更新时间:2023-10-28 23:26:32 27 4
gpt4 key购买 nike

我想获取每个 Android 设备唯一的设备 ID。我目前正在为平板设备开发。想要获取唯一的设备id并存储对应的值...

所以,我想知道如果我使用 TelephonyManager.getDeviceId()...,平板设备是否会返回一个值...???或者是否有任何其他值对每个设备都是唯一的???

最佳答案

TelephonyManger.getDeviceId() 返回唯一的设备 ID,例如,GSM 的 IMEI 和 CDMA 手机的 MEID 或 ESN。

final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);            
String myAndroidDeviceId = mTelephony.getDeviceId();

但我建议使用:

Settings.Secure.ANDROID_ID,将 Android ID 作为唯一的 64 位十六进制字符串返回。

    String   myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID); 

有时 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;
}

关于android - TelephonyManger.getDeviceId() 是否会为 Galaxy Tab 等平板电脑返回设备 ID ...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3802644/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com