Is there any alternative way for getting IMEI number which wont give me obsolete warning?

judsonabrahamjudsonabraham USMember ✭✭✭

Hi I want to get IMEI number in my Android device.And I'm able to do it. But I'm getting obsolete warning saying** 'TelephonyManager.DeviceId' is obsolete:'deprecated'**. I'm using this code to get IMEI number in my Android device

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

            return mTelephonyMgr.DeviceId;

right now I'm able to disable the obsolete warning by using

     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

But why I'm getting this obsolete warning? Is there a different approach for getting IMEI number where I wont get this obsolete warning?

Best Answer

  • judsonabrahamjudsonabraham US ✭✭✭
    edited January 1 Accepted Answer

    I'm creating a Tracking app which fetches the IMEI number of the device and tracks it. I have fixed the issue.This is my code

    Android.Telephony.TelephonyManager mTelephonyMgr;
                                mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);
    
    return mTelephonyMgr.Imei;
    

    This doesn't show me any obsolete warning.

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Out of personal curiosity only... Why does your app need that kind of information? It seems very invasive.

  • judsonabrahamjudsonabraham USMember ✭✭✭
    edited January 1 Accepted Answer

    I'm creating a Tracking app which fetches the IMEI number of the device and tracks it. I have fixed the issue.This is my code

    Android.Telephony.TelephonyManager mTelephonyMgr;
                                mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);
    
    return mTelephonyMgr.Imei;
    

    This doesn't show me any obsolete warning.

Sign In or Register to comment.