简体   繁体   English

Gettig 空白 IMEI 使用 Visual Studio 2017 和 Xamarin

[英]Gettig Blank IMEI Using Visual Studio 2017 and Xamarin

I am Trying to getting IMEI num of Device using this code.我正在尝试使用此代码获取设备的 IMEI 编号。 When I am Deployint my app I get blank Deviceid where as i am getting devicesoftware version correctly当我 Deployint 我的应用程序时,我得到空白 Deviceid,因为我正在正确获取 devicesoftware 版本

Android.Telephony.TelephonyManager mTelephonyMgr;
            mTelephonyMgr = (Android.Telephony.TelephonyManager)GetSystemService(Context.TelephonyService);
            m_deviceId = mTelephonyMgr.DeviceId;
 

from the docs文档

This method was deprecated in API level 26. Use getImei() which returns IMEI for GSM or getMeid() which returns MEID for CDMA.此方法在 API 级别 26 中已弃用。使用 getImei() 返回 GSM 的 IMEI 或 getMeid() 返回 MEID 的 CDMA。

What you need to do is simple你需要做的很简单

Android.Telephony.TelephonyManager mTelephonyMgr;
mTelephonyMgr = (Android.Telephony.TelephonyManager)GetSystemService(Context.TelephonyService);

if (Android.OS.Build.VERSION.SdkInt>= BuildVersionCodes.O)
        {
            m_deviceId = mTelephonyMgr.Imei;
        }
        else
        {
            m_deviceId = mTelephonyMgr.DeviceId;
        }

Also make sure you have read phone state permission:还要确保您已阅读电话 state 权限:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

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

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