How to Get IMEI in Android Programmatically?

Did you ever spend hundreds of bucks to get something done on the android device that you couldn’t do for not having the proper knowledge? Or have you wasted countless hours sitting confused trying to figure out how to get it done?

Well, you don’t have to worry anymore. You have stumbled upon the right people. Today, we will find out how to get IMEI in android programmatically.

IMEI, also known as International mobile equipment identity, is a unique number that every mobile in the world has. It is usually used to manage and identify phones. Unfortunately, the correct process of finding IMEI programmatically is very less discussed.

As a result, many of us find it hard to get IMEI on android. So this guide is all about learning a few different ways of getting it manually with step-by-step guide.

Step by Step Guide on How to Get IMEI in Android Programmatically:

How to Get IMEI in Android Programmatically

So for the first way, we are going to be using TelephonyManager. It provides access to information about the telephony services on the device. There are two ways of getting IMEI using TelephonyManager and we will be discussing both.

So let’s get straight into it:


Call android.telephony.TelephonyManager.getDeviceId().

It would look into its database and return whichever unique numbers identify the device. It usually is IMEI for GSM and MEID for CDM.


You need to use the following permission in your AndroidManifest.xml:

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

This has to be done if you want this process to work.


You should also add the following code in your AndroidManifest.xml

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

We recommend adding this because in the emulator, you might get a value like “0000….”. As getDeviceId() returns null if the device Id is not available.

Moreover, you can also use the following code to get IMEI on your android device programmatically.


Enter the code given below:

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

String device_id = tm.getDeviceId();


Add the following permission in Android Manifest:


This is more like the way easier way of getting your IMEI without having to ask anyone or pay anyone to do it.

How to Get IMEI Number in Android Studio Programmatically

How to Get IMEI in Android Programmatically

So, for the second way, we are going to be working with Android Studio. In a nutshell, it is an android device’s official IDE. The main objective for android studio is to accelerate your development and aid you in building a good quality app. Today we are going to be using it to get our android device’s IMEI.

Follow the steps given below:


Start android studio and create a new project. For that go to Files⇒ New project and fill in all the required details to create a new project.


Add the following code to res/layout/activity_main.xml.

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android=""







      android:text="Check IEMI number"









      android:hint="Your IEMI number"






So, for the next step, we are going to add the following code to src/

import android.Manifest;

import android.content.Context;





import android.os.Bundle;

import android.telephony.TelephonyManager;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

   Button button;

   TextView textView;

   String IMEINumber;

   private static final int REQUEST_CODE = 101;


   protected void onCreate(Bundle savedInstanceState) {



      textView = findViewById(;

      button = findViewById(;

      button.setOnClickListener(new View.OnClickListener() {


         public void onClick(View v) {

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

            if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {

               ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_CODE);



            IMEINumber = telephonyManager.getDeviceId();






   public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {

      switch (requestCode) {

         case REQUEST_CODE: {

            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

               Toast.makeText(this, "Permission granted.", Toast.LENGTH_SHORT).show();

            } else {

               Toast.makeText(this, "Permission denied.", Toast.LENGTH_SHORT).show();






Then lastly, we are going to add this to androidManifest.xml

<manifest xmlns:android="" package="">

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








      <activity android:name=".MainActivity">


            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />





By doing this, we have created an application that will help us get our IMEI. Hopefully, you have connected your actual mobile device with your computer. As for running this, start the app from android studio, open one of your project’s activity files and click the “Run” icon from the toolbar.

Select your mobile device as an option and then check your display. What you should be seeing is: 

How to Get IMEI in Android Programmatically

And here you go, we just created an app to see your device’s IMEI for free!

Frequently Asked Questions (F.A.Q’s)

Can Android 10 get programmatically IMEI number?

Yes, It can. But as for starting android 10, apps must have

READ_PRIVILEGED_PHONE_STATE privileged permission for accessing the device’s non-changeable identifiers. This includes both IMEI and serial numbers.

Is IMEI number unique?

Yes, it is. Think of it as your phone’s face id. It is a 15 digit number completely unique to your phone. Indeed, phone manufacturers and carriers share IMEI to enable tracking of stolen or compromised phones.

Can android apps read IMEI?

Not always. In order to do so, you must grant the app READ_PHONE_STATE permission. Only then, the app will be able to access the IMEI.

How can I get my IMEI number?

If you want to find your IMEI normally without programming, go to settings. Then scroll down and select about the phone. Scroll down to the bottom to find your IMEI number.

How to find IMEI number without my phone?

In case you lost your mobile device but did not copy your IMEI number, you can still retrieve it from your google accounts. Just go to google settings, sign in and expand the android tab.

Here, you can see you have connected every device to your google account. All the IMEI numbers of the devices connected will be right there as well.


Hopefully, you’ve learned how to get IMEI in android programmatically. If not, then go over the article and give that a read once again. The processes mentioned above are by far the easiest way of finding IMEI with minimum requirements. The steps mentioned above almost work on every android version so don’t worry we got you covered.

No matter whichever process you choose to follow, just make sure you do every step correctly without any error to get IMEI on your android device. 

By Rakib Ahmed

Hello, I am Rakib Ahmed, a former army commando of UNICEF. I left My Job And start blogging. Blogging has become my passion nowadays. I love technology. In today's life, I found several problems related to technology but can't get good solutions at all. That's Why Fixwill Journey Started. Stay Connected And Get Great Solution About Android,IOS,Windows Linux And Many more tech Solution. Thank You dear!