Home Forum
Welcome, Guest
Username Password: Remember me

Get the handsets phone number in code
(1 viewing) (1) Guest
Discussion related to creating Android software
  • Page:
  • 1

TOPIC: Get the handsets phone number in code

Get the handsets phone number in code 3 years, 5 months ago #4

Is this possible?

Re:Get the handsets phone number in code 3 years, 5 months ago #23

You could try calling getLine1Number() on the class android.telephony.TelephonyManager

For example:
android.telephony.TelephonyManager mgr = Context.getSystemService(Context.TELEPHONY_SERVICE);

String myMSISDN = mgr.getLine1Number();


Have a look here for some other very interesting telephony functions code.google.com/android/reference/androi...elephonyManager.html
  • mmoore
  • OFFLINE
  • Examiner
  • Posts: 22
  • Karma: 1

Re:Get the handsets phone number in code 2 years, 9 months ago #179

I tried this myself and ran into a few issues, firstly to call the TelephonyManager members you need to add a permission to the android manifest

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


Also you may find that outside the emulator that getLine1Number returns an empty string.

For an explanation see this link, but in a nutshell the sim card does not know its number but can make an educated guess.

groups.google.com/group/android-develope...294350ea14e?lnk=raot

So you can call this function if you want to add the permission, but make sure you test the result before confidently displaying the results!
  • mmoore
  • OFFLINE
  • Examiner
  • Posts: 22
  • Karma: 1
Last Edit: 2 years, 9 months ago by mmoore.
  • Page:
  • 1
Time to create page: 0.24 seconds
Copyright © 2012 Android Academy. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.
 
Glossary
We have 30 guests online