How to get IMSI in Android 10 (Android Q)

635 Views Asked by At

I'm unable to get IMSI in Android 10.

The Code that I was using to fetch IMSI number is giving an exception. java.lang.SecurityException: getSubscriberId: The user 10099 does not meet the requirements to access device identifiers. I understand that from android 10, google has restricted this information and its not accessible to third party apps due to privacy concerns but I'm looking for a workaround. The code that I was using is:

private void getImsiNumber()
    {
        Utility.DEBUG_LOG(TAG,"+ getImsiNumber +");
        if ( this.imsiNumber == null )
        {
            Utility.DEBUG_LOG(TAG,"step 1");
            TelephonyManager telephonyManager = (TelephonyManager) DashboardContainer.this.getSystemService(Context.TELEPHONY_SERVICE);
            Utility.DEBUG_LOG(TAG,"step 2");
            try {
                this.imsiNumber = telephonyManager.getSubscriberId();
                Utility.DEBUG_LOG(TAG,"step 3");
                if ( this.imsiNumber == null  || this.imsiNumber.length() == 0 )
                {
                    Utility.DEBUG_LOG(TAG,"imsiNumber:"+this.imsiNumber);
                    this.imsiNumber = "WiFi";
                }
            }
            catch (Exception e )
            {
                Utility.DEBUG_LOG(TAG,"Exception:"+e.getMessage().toString());
            }
            Utility.DEBUG_LOG(TAG,"IMSI Number:"+this.imsiNumber);
            SharedPref.write("imsiNumber",this.imsiNumber);
            Constants.IMSI_NO = this.imsiNumber;
        }

    }
0

There are 0 best solutions below