javaandroidgoogle-api-clientandroid-googleapiclient

How to get phone number of the device in android activity


Is there any way to get phone number of device, by using GoogleApiClient. I got email, now want phone number.


Solution

  • Add this permission:

    <uses-permission android:name="android.permission.READ_PHONE_STATE"/> 
    

    and later use this:

    TelephonyManager t = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
    String mPhoneNumber = t.getLine1Number();
    

    Note: This method - although one of the only ways to do it - is not reliable. It can return a false number, blank string, or even null.