1

I need phone numbers while developing my application. So, I used TelephonyManager as seen below:

TelephonyManager tmgr =(TelephonyManager)getApplicationContext().getSystemService(getApplicationContext().TELEPHONY_SERVICE);
Log.d("Tag", tmgr.getLine1Number());

But when I tried application in different devices, somehow getLine1Number() not working. I mean returns NULL.

Permission is okay. Finally, does getLine1Number() depend on other requirements? Is it possible to learn phone number on every device.

Thanks for advices.

Ogulcan Orhan
  • 5,170
  • 6
  • 33
  • 49

1 Answers1

4

it is not possible to get phone number on every device because this depends on how sim card is made. This is a sim card limitation.

Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
  • First, thank you gabi. Can you give me more detail about this state? – Ogulcan Orhan Feb 28 '12 at 15:40
  • 3
    There is no guaranteed solution to this problem because the phone number is not physically stored on all SIM-cards, or broadcasted from the network to the phone. This is especially true in some countries which requires physical address verification, with number assignment only happening afterwards. Phone number assignment happens on the network - and can be changed without changing the SIM card or device (e.g. this is how porting is supported). I know it is pain, but most likely the best solution is just to ask the user to enter his/her phone number once and store it. – Buda Gavril Feb 28 '12 at 15:43
  • this is an answer from question http://stackoverflow.com/questions/2480288/get-phone-number-in-android-sdk – Buda Gavril Feb 28 '12 at 15:44
  • You should also remember that it's completely possible your user will be running a tablet. – Kristopher Micinski Feb 28 '12 at 15:51