Reputation: 15021
Is there a way to retrieve the user's phone number in an mobile app? I'm looking to build some sort of addressbook utility that builds phone numbers and let them dial the numers etc by making use of their current phone number. Is there a way to retrieve this information?
I've found some ways to retrieve it in blackberry and android from the sim card, but apparently the value in the sim card does not guarantee that its actually their number.
Upvotes: 1
Views: 1096
Reputation: 15313
For blackberry you can use
Phone.getDevicePhoneNumber(false)
According to javadoc , this method can return null if no phone number is currently available
There is one general workaround for getting user's mobile number.
Upvotes: 2
Reputation: 207863
You can use the TelephonyManager
to do this:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String number = tm.getLine1Number();
The documentation for getLine1Number()
says this method will return null
if the number is "unavailable", but it does not say when the number might be unavailable.
You'll need to give your application permission to make this query by adding the following to your Manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
(You shouldn't use TelephonyManager.getDefault()
to get the TelephonyManager
as that is a private undocumented API call and may change in future.)
Upvotes: 3