Find / Get imei number in android programmatically

Find and display android mobile device imei number using TelephonyManager.

IMEI number also known as International mobile equipment identity is the unique number of every mobile phone in the whole world. The imei number is used to manage and identify the mobile phone. On android app we can easily get the current mobile device imei number using TelephonyManager class. So here is the complete step by step tutorial for Find / Get imei number in android programmatically.

android-project-download-code-button

How to Find / Get imei number in android programmatically.

Note : Please add READ_PHONE_STATE permission inside AndroidManifest.xml file.

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

Code for MainActivity.java file.

 package com.getimeinumber_android_examples.com;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

 TextView imei_number;
 Button get_imei;
 String IMEI_Number_Holder;
 TelephonyManager telephonyManager;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 imei_number = (TextView)findViewById(R.id.textView1);
 get_imei = (Button)findViewById(R.id.button1);
 
 telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
 get_imei.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 IMEI_Number_Holder = telephonyManager.getDeviceId();
 
 imei_number.setText(IMEI_Number_Holder);
 }
 });
 
 }

}

Code for activity_main.xml file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.getimeinumber_android_examples.com.MainActivity" >

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textView1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="24dp"
 android:text="Click here to get imei number in android programmatically" />

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="170dp"
 android:gravity="center"
 android:text="Your IMEI Number Display Here"
 android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Code for AndroidManifest.xml file.

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.getimeinumber_android_examples.com"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
 android:minSdkVersion="8"
 android:targetSdkVersion="21" />

 <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
 <application
 android:allowBackup="true"
 android:icon="@drawable/ic_launcher"
 android:label="@string/app_name"
 android:theme="@style/AppTheme" >
 <activity
 android:name=".MainActivity"
 android:label="@string/app_name" >
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />

 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>
 </application>

</manifest>

Screenshot:

Get imei number in android programmatically

Click here to download Find / Get imei number in android programmatically project

4 Comments

  1. This method works for android 6+?

  2. Norman Younghusband

    getdeviceid() is not working in API level 23. What is the remedy out?

Leave a Reply

Your email address will not be published. Required fields are marked *