Use TelephonyManager. getLine1Number ()
But you need to save the phone number on the SIM card , and there is no other way to get your own number.
Example:
TelephonyManager tm = (TelephonyManager)this.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String myPhoneNumber = tm.getLine1Number();
and you need this permission in your Manifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
See this question:
Error TelephonyManager.getLine1Number ()? as described, you need to evaluate:
if("SIM card present" && "phone number is stored") {
"get the phone number with TelephonyManager.getLine1Number"
}
source
share