tm.getDeviceId()已弃用? [英] tm.getDeviceId() is deprecated?
问题描述
我正在获取 IMEI
和设备ID,所以我在这里遇到问题 getDeviceId()
是弃用。
I'm getting the IMEI
and device Id's, so here I am getting a problem getDeviceId()
is deprecated.
TelephonyManager tm = (TelephonyManager)
getSystemService(this.TELEPHONY_SERVICE);
imei = tm.getDeviceId();
device = Settings.Secure.getString(this.getContentResolver(),
Settings.Secure.ANDROID_ID);
推荐答案
getDeviceId( )
getDeviceId()
返回订阅的唯一设备ID,例如GSM的IMEI和CDMA手机的MEID。如果设备ID不可用,则返回null。
Returns the unique device ID of a subscription, for example, the IMEI for GSM and the MEID for CDMA phones. Return null if device ID is not available.
API级别26中的此方法已弃用。
This method was deprecated in API level 26.
使用 (@ link getImei}
,返回 IMEI
GSM
Use (@link getImei}
which returns IMEI
for GSM
或 (@ link getMeid}
,为 返回
。 MEID
CDMA
or (@link getMeid}
which returns MEID
for CDMA
.
了解更多信息 TelephonyManager
for more information read TelephonyManager
试试这个以获取IMEI
Try this to get IMEI
@RequiresApi(api = Build.VERSION_CODES.O)
TelephonyManager tm = (TelephonyManager)
getSystemService(this.TELEPHONY_SERVICE);
String imei = tm.getImei();
OR
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String imei = telephonyMgr.getImei();
} else {
String imei = telephonyMgr.getDeviceId();
}
试试这个
MEID
@RequiresApi(api = Build.VERSION_CODES.O)
TelephonyManager tm = (TelephonyManager)
getSystemService(this.TELEPHONY_SERVICE);
String meid=tm.getMeid();
OR
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String meid=tm.getMeid();
}
这篇关于tm.getDeviceId()已弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!