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?
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.)