1

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 the help of this i want to read user phone number from his/her SIM card i also add READ_PHONE_STATE permission in manifest file. Eclipse showing no error in my code but still i get nothing in the end. Is there anything wrong with my code?

  • Not all companies will provide / enable the phone number in the SIM or even in the phone. In my galaxy s2, I can't see my phone number even going in the settings menu... – woliveirajr Jul 23 '13 at 12:46
  • After doing some research, I found that phone numbers are not actually stored in the SIM cards. Phone numbers are retrieved from vendor network through unique key that each SIM card has. For more discussion on this topic, reach the thread linked on right side. – Irfan Jul 23 '13 at 12:48

1 Answers1

0

See this thread for more information on this issue. Specifically, the below comment on the accepted answer:

Actually, not so perfect. Last time I tried this method, it reported the phone number that my phone originally had, before my old mobile number was ported over to it. It probably still does, as the Settings app still shows that defunct number. Also, there are reports that some SIMs cause this method to return null. That being said, I'm not aware of a better answer. – CommonsWare

It seems that getting a user's phone number is not as simple as asking the OS to hand it over, for reasons beyond the control of the developer. An alternative is to populate whichever field you need with the number the OS gives, but also let the user edit the phone number in case the OS is wrong.

Community
  • 1
  • 1
ironicaldiction
  • 1,200
  • 4
  • 12
  • 27