Use:
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"/>
EDIT:
try using getSimSerialNumber()
getLine1Number()
- this method returns the phone number string for line 1, i.e the MSISDN
for a GSM
phone. Return null if it is unavailable.
this method works only for few cell phone but not all phones.
So, if you need to perform operations according to the sim(other than calling), then you should use getSimSerialNumber()
. It is always unique, valid and it always exists.
String sSimSerial = mTelephonyMgr.getSimSerialNumber();