-1

I want to build a web based android app. What I want is I want my app to know the user phone number, but I don’t want them to enter it; perhaps, I want my app automatically know their number, by accessing their SIM Card or whatever way. Can you help me please?

Thank you.

B3738
  • 51
  • 1
  • 1
  • 10
  • http://stackoverflow.com/questions/5948446/to-get-phone-number-programatically-in-android try to surf through the site before asking question – SVS Sep 03 '13 at 13:58

1 Answers1

1

Manifest permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Code:

TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String telNumber = manager.getLine1Number();

this does not mean that it will work on every device. Sometime number is just unavailable.

kjurkovic
  • 4,044
  • 2
  • 23
  • 28
  • 1
    Also note that some users are weary of apps which ask for this permission without any obvious need for it. – 323go Sep 03 '13 at 13:58
  • 1
    The number may also be wrong -- my SIM reports a phone number that was from when I first provisioned the phone, but my real phone number is something else, ported over from another carrier. The device does not need to know the user's phone number to be able to accept incoming calls. – CommonsWare Sep 03 '13 at 13:59
  • The reason I want the phone number is because I want my app to send a message and I don't my app to ask the user what their number is. So What is the best solution? – B3738 Sep 09 '13 at 12:33
  • actually the best solution is to ask your user for a phone number. As you can see from the posted comments, the OS cannot guarantee that you will get the correct number from a SIM card or that you will get a phone number at all. – kjurkovic Sep 09 '13 at 12:52