Exemple #1
0
        public string GetIdentifier()
        {
            String ret = "";

            try
            {
                String strDeviceId = Android.Provider.Settings.Secure.GetString(Forms.Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId);

                Context          contexto         = Android.App.Application.Context;
                TelephonyManager telephonyManager =
                    (TelephonyManager)contexto.GetSystemService(Context.TelephonyService);


                if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.O)
                {
                    try
                    {
                        ret = telephonyManager.GetDeviceId(0);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            ret = telephonyManager.GetDeviceId(1);
                        }
                        catch (Exception)
                        {
                            ret = telephonyManager.DeviceId;
                        }
                    };
                }
                else
                {
                    try
                    {
                        ret = telephonyManager.GetImei(0);
                        if (ret == null)
                        {
                            ret = strDeviceId;
                        }
                    }
                    catch (Exception)
                    {
                        try
                        {
                            ret = strDeviceId; //telephonyManager.GetImei(1);
                            //if (ret == null)
                            //    ret = strDeviceId;
                        }
                        catch (Exception)
                        {
                            ret = telephonyManager.Imei;
                        }
                    };
                }
            }
            catch (Exception) { }

            return(ret);
        }
        public UserDeviceModel GetIdentifier(int simSlot)
        {
            UserDeviceModel info = new UserDeviceModel();

            try
            {
                TelephonyManager IMEI_telManager = (TelephonyManager)Forms.Context.GetSystemService(Context.TelephonyService);
                if (IMEI_telManager != null)
                {
                    info.DeviceInformation.IMEI        = IMEI_telManager.GetDeviceId(simSlot);
                    info.DeviceInformation.PhoneNumber = IMEI_telManager.Line1Number;
                }
            }
            catch (Exception)
            {
            }

            return(info);
        }