Get Phone Number in Android via Code

by Sasikumar 2014-04-28 16:16:13

Get phone number of the android device using code :
public String getPhoneNumber() {
TelephonyManager myTelephonyManager;
myTelephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
return myTelephonyManager.getLine1Number();
}
public String getPhoneNumberIn10Digit(){
String s = getPhoneNumber();
return s.substring(2);
}

To access the phone state we need to declare the permission in android manifest file, use the following code in android manifest file,
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Make a call to "getPhoneNumberIn10Digit()" function in your activity to get the phone number of the device.
1107
like
0
dislike
0
mail
flag

You must LOGIN to add comments