File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 214
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?
jQuery in Action, 3rd edition