Programmatically obtain the phone number of the Android phone

jkap picture jkap · Mar 19, 2010 · Viewed 446.3k times · Source

How can I programmatically get the phone number of the device that is running my android app?

Answer

Alex Volovoy picture Alex Volovoy · Mar 19, 2010

Code:

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

Required Permission:

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

Caveats:

According to the highly upvoted comments, there are a few caveats to be aware of. This can return null or "" or even "???????", and it can return a stale phone number that is no longer valid. If you want something that uniquely identifies the device, you should use getDeviceId() instead.