1
TelephonyManager manager1 = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String strMobile1 = manager1.getLine1Number();  

This is my code for getting mobile number of but its not working. I have also take necessary permission in manifest file

2
  • What is the error you are experiencing?
    – Jared
    Sep 16, 2014 at 5:15
  • There is no error but i am not getting mobile number
    – Niraj
    Sep 16, 2014 at 5:29

2 Answers 2

0

We had the same problem in our project. The conclusion was that it depends on the SIM card.

What happened to us:

Galaxy S with AT&T SIM card: can read phone number, Settings shows number
Same Galaxy with an European SIM card: cannot read the number and "unknown" in Settings (cell phone was perfectly functional, just couldn't read the number)
This has been reported in other forums as well.

In the end we decided to ask the user for the phone number. A bit more involved, actually: if( "SIM card present" && "cannot read the cell number") "ask user"; . Otherwise we will keep bugging the user that doesn't a SIM card in the first place.

getLine1Number() only get the number stored on the sim card..a lot of operators don't write there the sim number..on some phones (nokia, blackberry, some olds android, iphone) you can set your own mobile number and the phone will store it on the sim card, at that point getLine1Number() will return the phone number
0

The method you are using is the only one part of the SDK to do this, and only works on devices where the number is stored on the SIM card, which only some carriers do.

For all other carriers, you will have to ask the user to enter the phone number manually, as the number is simply not stored anywhere on the device from where you can retrieve it.

source here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.