Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current SIM card number in Android?

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?

like image 976
User Avatar asked Dec 27 '12 07:12

User


People also ask

How do I find my SIM card number on Android?

Find My SIM Card Number on an AndroidGo to Settings > About Phone > Status, then scroll down and locate the ICCID (SIM Card) number.

How do I find my 18 digit SIM number?

It's a unique 18-22 digit code that includes a SIM card's country, home network, and identification number. You'll usually find an ICCID printed on the back of a SIM card, but sometimes it's included in the packaging materials instead.


2 Answers

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.

like image 192
Dipak Keshariya Avatar answered Sep 28 '22 02:09

Dipak Keshariya


Getting the Phone Number, IMEI, and SIM Card ID

TelephonyManager tm = (TelephonyManager)              getSystemService(Context.TELEPHONY_SERVICE);         

For SIM card, use the getSimSerialNumber()

    //---get the SIM card ID---     String simID = tm.getSimSerialNumber();     if (simID != null)         Toast.makeText(this, "SIM card ID: " + simID,          Toast.LENGTH_LONG).show(); 

Phone number of your phone, use the getLine1Number() (some device's dont return the phone number)

    //---get the phone number---     String telNumber = tm.getLine1Number();     if (telNumber != null)                 Toast.makeText(this, "Phone number: " + telNumber,          Toast.LENGTH_LONG).show(); 

IMEI number of the phone, use the getDeviceId()

    //---get the IMEI number---     String IMEI = tm.getDeviceId();     if (IMEI != null)                 Toast.makeText(this, "IMEI number: " + IMEI,          Toast.LENGTH_LONG).show(); 

Permissions needed

<uses-permission android:name="android.permission.READ_PHONE_STATE"/> 
like image 20
Anil gangwar Avatar answered Sep 28 '22 02:09

Anil gangwar