Get my Telephone number in ANDROID

By | October 5, 2010

Gets the phone number the app is running on. It needs a permission so add the line uses-permission android:name=”android.permission.READ_PHONE_STATE” to the manifest.xml

private String getMyPhoneNumber(){
        TelephonyManager mTelephonyMgr;
        mTelephonyMgr = (TelephonyManager)
        getSystemService(Context.TELEPHONY_SERVICE);
        return mTelephonyMgr.getLine1Number();
}

private String getMy10DigitPhoneNumber(){
      String s = getMyPhoneNumber();
      return s.substring(2);
}

Leave a Reply

Your email address will not be published. Required fields are marked *