Getting a phone number from a SIM card

This is my code.

TelephonyManager mTelephonyMgr = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); String sDeviceID = mTelephonyMgr.getDeviceId(); String sSimSerial = mTelephonyMgr.getSimSerialNumber(); String sSimlineNumber = mTelephonyMgr.getLine1Number(); 

with this, I want to read the user's phone number from my SIM card, and also add READ_PHONE_STATE to the manifest file. Eclipse does not show errors in my code, but still I get nothing at the end. Is there something wrong with my code?

+1
source share
1 answer

See this thread for more on this issue. In particular, the comment below on the accepted answer:

Actually, not so perfect. The last time I tried this method, he reported the phone number that my phone had before my old mobile number was transferred to it. This is probably the case since the settings app still shows this invalid number. There are also reports that some SIM cards force this method to return null. However, I do not know a better answer. - CommonsWare

It seems that getting a user's phone number is not as simple as asking the OS to transfer it for reasons beyond the control of the developer. An alternative is to fill in any field that you need with the number that the OS provides, but also allows the user to edit the phone number in case of incorrect operation of the OS.

0
source

All Articles