This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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

how to get phone number from my app?

Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 213
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 has stopped unexpectedly. please try again.

Any solution would be greatly appreciated.



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
I agree. Here's the link:
subject: how to get phone number from my app?
Similar Threads
capturing windows app's output
Reflection got at field editing exception
Number Format
To get a number from html page
How this app working?