NAVIGATION - SEARCH

Android - How To Get IMEI SIM Card ID And SIM Card Country Code

There can be a scenario where you would want to extract Android phone IMEI number or SIM card ID to ensure uniqueness of install or to write some security feature where if someone tries to change SIM card then you gets a notification. Also you may use SIM card country code to get the source country of app install. This article will explain about how to extract or get the IMEI number, SIM card ID or even the SIM card country code.

To get these details about your phone, you need to obtain an instance of the TelephonyManager class:

public class MainActivity extends Activity 
{
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
	}
}

To get the SIM card ID, use the getSimSerialNumber() method of the TelephonyManager object:

String simid = mTelephonyManager.getSimSerialNumber();
if (simid != null)
{
	Toast.makeText(this, "SIM Card ID: " + simid, Toast.LENGTH_LONG).show();
}

To get the phone number of your phone, use the getLine1Number() method of the TelephonyManager object:

String phonenumber = mTelephonyManager.getLine1Number();
if (phonenumber != null)
{
	Toast.makeText(this, "Phone Number: " + phonenumber, Toast.LENGTH_LONG).show();
}

To get the IMEI number of the phone, use the getDeviceId() method of the TelephonyManager object:

String imeinumber = mTelephonyManager.getDeviceId();
if (imeinumber != null)
{
	Toast.makeText(this, "IMEI Number: " + imeinumber, Toast.LENGTH_LONG).show();
}

To get the SIM card ISO country code of the phone, use the getSimCountryIso() method of the TelephonyManager object:

String isocode = mTelephonyManager.getSimCountryIso();
if (isocode != null)
{
	Toast.makeText(this, "Country ISO Code: " + isocode, Toast.LENGTH_LONG).show();
}

In order to obtain the SIM card ID, phone number, and device ID, you need to add the READ_PHONE_STATE permission to the AndroidManifest.xml file

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

Add comment