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.)