Android Priya Android Priya - 1 year ago 222
Android Question

How to get phone no of device programmatically

I am trying to get phone no using following method:

private String getMyPhoneNumber(){
TelephonyManager mTelephonyMgr;

mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
//String imsi = mTelephonyMgr.getSubscriberId();
String phnNo=mTelephonyMgr.getLine1Number();
if (phnNo==null) {
phnNo= getNoFromWatsApp();

return phnNo;
private String getNoFromWatsApp(){
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccounts();
String phoneNumber="";

for (Account ac : accounts) {
String acname =;
String actype = ac.type;
// Take your time to look at all available accounts
phoneNumber =;
return phoneNumber;

But every time i get phone no blank. I even tried to get phone no from wats app but its returing "WatsApp" instead of phone no.
Is there any other way to solve this problem?

Answer Source

Use below code :

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

In AndroidManifest.xml, give the following permission:

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

But remember, this code does not always work, since Cell phone number is dependent on the SIM Card and the Network operator / Cell phone carrier.

Also, try checking in Phone--> Settings --> About --> Phone Identity, If you are able to view the Number there, the probability of getting the phone number from above code is higher. If you are not able to view the phone number in the settings, then you won't be able to get via this code!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download