android getLine1Number() returns empty string

ABI picture ABI · Mar 16, 2015 · Viewed 8.5k times · Source

I want to get the mobile number of users, which will be defaultly taken as username, when I used the following code to get the mobile number, it returns an empty string

TelephonyManager tMgr = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
            mPhoneNumber = tMgr.getLine1Number();
            String mobNo = mPhoneNumber.replace("+", "");

One reason I found is My phone number is unknown under Settings->About Phone->Status->SIM Status. How to rectify this issue without giving any burden to the users.

enter image description here

Answer

sstn picture sstn · Mar 16, 2015

There are at least some SIM Cards/Operators out there who don't provide numbers - I have seen it and you have seen it. There is probably nothing you can do about it.