Search code examples
androidtelephonymanager

How to find the mobile phone number in android?


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


Solution

  • 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