How to find the mobile phone number in android?

6.9k Views Asked by At

I am developing a small android application in that i want find the mobile phone number used in the particular phone

I tried the following

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

It is working fine in Emulator but It is not working in my phone

please help me anyone how to do that

3

There are 3 best solutions below

0
On BEST ANSWER

You may want to look at this question, there is probably no better way, and you may need to ensure that your app has the READ_PHONE_STATE permission, but, your SIM may not be returning it.

I would be nervous about any phone trying to get this value. Why do you need it, there may be a better way to do what you want.

Programmatically obtain the phone number of the Android phone

0
On

I disagree with all the answers here. Since practically these api's dont work consistently. So if your app is heavily dependent on the phone number, you must ask for it. Be prepared to ask for this work around manually, just incase you dont get the number.

Samsung phones for example are inconsistent with their API's across their phones. Some phones work and some dont. As compared to HTC or LG they are more consistent with their API's since they dont fiddle with the lower layer at all.

0
On

the most simple way to know automatically a phone's number is to write an app to send a SMS. I use IMEI and some content to automatically capture the phone's number. I have a small SMS server and use it to update the DB. Asking phone number to a user is not realiable... The Imei is simple to obtain and combining to phone number is the right choice!