This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Android and the fly likes how to get phone number from my app? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "how to get phone number from my app?" Watch "how to get phone number from my app?" New topic
Author

how to get phone number from my app?

Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 213
hi,
is it possible to retrieve my mobile number through my andriod app?
if so please suggest
Mohan Prasath
Ranch Hand

Joined: Jul 25, 2011
Posts: 38

The following code would do!. But be sure to insert Null Checks for the result.

String phoneNo = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).getLine1Number();

Also insert the following permission in AndroidManifest file.

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


With regards,
Mohan Prasath
Satchidananda Mohanty
Ranch Hand

Joined: Mar 12, 2008
Posts: 77

Hi ,

I have used the same and in emulator it shows one 9 digit number . In android phone application crashes and shows "The application(process xxx.xxx.xxx) has stopped unexpectedly. please try again.


Any solution would be greatly appreciated.

Thanks,


Zeet

SCJP 6.0
Naishadh Parmar
Ranch Hand

Joined: Jun 02, 2011
Posts: 95


Yeah, the one by Mohan Prasath will work. It would not work on an emulator because it does not support any sort of wireless connectivity. It would work on your phone
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to get phone number from my app?
 
Similar Threads
How this app working?
To get a number from html page
Number Format
Reflection got at field editing exception
capturing windows app's output