How to get the mobile number of current sim card in real device?

Narasimha picture Narasimha · Feb 5, 2010 · Viewed 115k times · Source

I have to make an application which shows the contact no of the SIM card that is being used in the cell. For that I need to use TelephonyManager class. Can I get details on its usage?

Answer

Dave Webb picture Dave Webb · Feb 5, 2010

You can use the TelephonyManager to do this:

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
String number = tm.getLine1Number();

The documentation for getLine1Number() says this method will return null if the number is "unavailable", but it does not say when the number might be unavailable.

You'll need to give your application permission to make this query by adding the following to your Manifest:

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

(You shouldn't use TelephonyManager.getDefault() to get the TelephonyManager as that is a private undocumented API call and may change in future.)