How to get phone number of the device in android activity

10,163

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.

Share:
10,163
Kuldeep
Author by

Kuldeep

I am a student, pursuing B.Tech(engineering) in Computer Science.

Updated on June 14, 2022

Comments

  • Kuldeep
    Kuldeep almost 2 years

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

  • josedlujan
    josedlujan over 8 years
    Not copy, i do this in my app a few days.
  • Louis Nguyen
    Louis Nguyen over 8 years
    Some device can not get phone number!
  • M090009
    M090009 about 8 years
    Don't forget that you'll need to ask for permission
  • Azhar osws
    Azhar osws over 7 years
    I am getting null? what is the problem?
  • Erich García
    Erich García over 6 years
    Sad, dont work for me, testing on Honor 9, and Sony Xperia