How to get current SIM card number in Android?

User picture User · Dec 27, 2012 · Viewed 105k times · Source

I want to know user mobile number in Android. I used this code but I'm not getting number.

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
        String n = tm.getLine1Number();

Permission:

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

Is it compulsory to save number in android mobile settings --> about phone --> status --> myphone number

Any idea on this?

Answer

Dipak Keshariya picture Dipak Keshariya · Dec 27, 2012

I think sim serial Number and sim number is unique. You can try this for get sim serial number and get sim number and Don't forget to add permission in manifest file.

TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String getSimSerialNumber = telemamanger.getSimSerialNumber();
String getSimNumber = telemamanger.getLine1Number();

And add below permission into your Androidmanifest.xml file.

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

Let me know if there is any issue.