有没有其他方法可以获取不会给我过时警告的 IMEI 号码?
Is there any alternative way for getting IMEI number which wont give me obsolete warning?
你好,我想在我的 Android 设备中获取 IMEI 号码。我可以做到。但是 我收到过时警告 说“TelephonyManager.DeviceId”已过时:'deprecated'。我正在使用此代码在我的 Android 设备
中获取 IMEI 号码
Android.Telephony.TelephonyManager mTelephonyMgr;
mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);
return mTelephonyMgr.DeviceId;
现在我可以使用
禁用过时警告
mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);
#pragma warning disable CS0618 // Type or member is obsolete
return mTelephonyMgr.DeviceId;
#pragma warning restore CS0618 // Type or member is obsolete
但为什么我会收到这个过时的警告?有没有不同的方法来获取 IMEI 号码,我不会收到这个过时的警告?
Definition 共 DeviceId
:
Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones. Return null if device ID is not available.
当 IMEI
只是:
IMEI (International Mobile Equipment Identity)
来自 Android official documentation it seems that DeviceId
is deprecated from API level 26 and that you should use GetMeid(int slotIndex)。在这种情况下,我会检查 API 级别,如果它低于 26,我仍然会使用 DeviceId
,否则 GetMeid(int slotIndex)
。
像这样:
string GetIMEI()
{
Android.Telephony.TelephonyManager mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
// TODO: Some phones has more than 1 SIM card or may not have a SIM card inserted at all
return mTelephonyMgr.GetMeid(0);
else
#pragma warning disable CS0618 // Type or member is obsolete
return mTelephonyMgr.DeviceId;
#pragma warning restore CS0618 // Type or member is obsolete
}
你好,我想在我的 Android 设备中获取 IMEI 号码。我可以做到。但是 我收到过时警告 说“TelephonyManager.DeviceId”已过时:'deprecated'。我正在使用此代码在我的 Android 设备
中获取 IMEI 号码Android.Telephony.TelephonyManager mTelephonyMgr;
mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);
return mTelephonyMgr.DeviceId;
现在我可以使用
禁用过时警告 mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);
#pragma warning disable CS0618 // Type or member is obsolete
return mTelephonyMgr.DeviceId;
#pragma warning restore CS0618 // Type or member is obsolete
但为什么我会收到这个过时的警告?有没有不同的方法来获取 IMEI 号码,我不会收到这个过时的警告?
Definition 共 DeviceId
:
Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones. Return null if device ID is not available.
当 IMEI
只是:
IMEI (International Mobile Equipment Identity)
来自 Android official documentation it seems that DeviceId
is deprecated from API level 26 and that you should use GetMeid(int slotIndex)。在这种情况下,我会检查 API 级别,如果它低于 26,我仍然会使用 DeviceId
,否则 GetMeid(int slotIndex)
。
像这样:
string GetIMEI()
{
Android.Telephony.TelephonyManager mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
// TODO: Some phones has more than 1 SIM card or may not have a SIM card inserted at all
return mTelephonyMgr.GetMeid(0);
else
#pragma warning disable CS0618 // Type or member is obsolete
return mTelephonyMgr.DeviceId;
#pragma warning restore CS0618 // Type or member is obsolete
}