简体   繁体   English

如何使用 android xamarin 从我的手机中恢复 IMEI

[英]How to recover the IMEI from my phone with android xamarin

I use IMEI = telephonyManager.Imei, but it is still null even if I took the permision Manifest.Permission.ReadPhoneState我使用IMEI = telephonyManager.Imei,但即使我使用了权限Manifest.Permission.ReadPhoneState,它仍然是null

TelephonyManager.DeviceId : TelephonyManager.DeviceId

Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones.返回唯一的设备 ID,例如,GSM 的 IMEI 和 CDMA 手机的 MEID 或 ESN。 Return null if device ID is not available.如果设备 ID 不可用,则返回 null。

I guess that telephonyManager.getDeviceId() is returned null with devices without sim card capabilities.我猜那 telephonyManager.getDeviceId() 被返回 null 与没有 sim 卡功能的设备。

In this case I would check the API level and if it is bellow 26 than I would still use DeviceId otherwise GetMeid(int slotIndex).在这种情况下,我会检查 API 级别,如果它低于 26,我仍然会使用 DeviceId,否则使用 GetMeid(int slotIndex)。

 string GetIMEI()
    {
        Android.Telephony.TelephonyManager mTelephonyMgr = (Android.Telephony.TelephonyManager)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

            return mTelephonyMgr.DeviceId;
    }

I use the code above, I can get IMEI number, and I don't have any issue.我使用上面的代码,我可以得到 IMEI 号码,我没有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM