How to Get the Unique ID of an Android Device? Last Updated : 31 Aug, 2022 Comments Improve Suggest changes Like Article Like Report There are different types of unique IDs present for a single android device. We can get IDs such as a device ID, IMEI which is also a unique ID, and many others. In this article, we will take a look at How to Get the Unique ID of an Android Device. Note: This Android article covered in both Java and Kotlin languages. Step by Step Implementation Step 1: Create a New Project in Android Studio To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Step 2: Working with the activity_main.xml file Navigate to app > res > layout > activity_main.xml and add the below code to it. Comments are added in the code to get to know in detail. XML <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/idRLContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <!--displaying a simple text view--> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@id/idTVUniqueID" android:layout_margin="15dp" android:text="Uniqie ID in Android" android:textAlignment="center" android:textColor="@color/black" android:textSize="20sp" android:textStyle="bold" /> <!--on below line creating text view for displaying id--> <TextView android:id="@+id/idTVUniqueID" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" android:padding="4dp" android:textAlignment="center" android:textSize="20sp" android:textStyle="bold" /> </RelativeLayout> Step 3: Working with the MainActivity file Navigate to app > java > your app's package name > MainActivity file and add the below code to it. Comments are added in the code to get to know in detail. Kotlin package com.gtappdevelopers.kotlingfgproject import android.os.Bundle import android.provider.Settings import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { // on below line we are creating variables. lateinit var uniqueIDTV: TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // on below line we are initializing our variables. uniqueIDTV = findViewById(R.id.idTVUniqueID) // on below line we are getting device id. val android_device_id = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) // on below line we are setting text // as our id to our text view. uniqueIDTV.text = android_device_id } } Java package com.gtappdevelopers.googlemapsroutes; import android.os.Bundle; import android.provider.Settings; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { // on below line we are creating variables. private TextView uniqueIDTV; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // on below line we are initializing our variables. uniqueIDTV = findViewById(R.id.idTVUniqueID); // on below line we are creating a variable to get unique id String android_device_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); // on below line setting id to our text view. uniqueIDTV.setText(android_device_id); } } Now run your application to see the output of it. Output: Comment More infoAdvertise with us Next Article How to Get the Unique ID of an Android Device? C chaitanyamunje Follow Improve Article Tags : Android Similar Reads How to Get the MAC of an Android Device Programmatically? MAC stands for Media Access Control. The MAC address is also known as the Equipment Id Number. This MAC Address is provided by the Network Interface Card. In this article, we will see step by step from creating a new empty project to How to make an android app to display MAC Address using Java. Note 2 min read How to Get the MAC of an Android Device using NetworkInterface Class? The MAC (Media Access Control) address in Android is a unique identifier assigned to the Wi-Fi module of the device. It is used to identify devices on a network and helps in network communication and security. The general method for getting the MAC address of the android device is using the Wifi Man 3 min read How to Get the Device's IMEI and ESN Programmatically in Android? Many times while building Android Applications we require a unique identifier to identify the specific mobile users. For identifying that user we use a unique address or identity. For generating that unique identity we can use the android device id. In this article, we will take a look at How to get 4 min read How to Ban an Android Device from Login to Your App? First of let's understand what is device ban feature device ban feature in Android allows administrators/developers to restrict specific devices from accessing an application or service. This is crucial for maintaining security and enforcing policies. Why Device Bans are Important?Let's take an exam 6 min read How to Get the Build Version Number of an Android Application? Version Name and Version Code in an Android application tell us about the current app version installed on the user's mobile device. This information is generally used when we prompt users to update to the new version of the older version of the application. In this article, we will look at How to g 3 min read How to Fetch Device ID in Android Programmatically? The android Device ID is a unique code, string combinations of alphabets and numbers, given to every manufactured android device. This code is used to identify and track each android device present in the world. In Android, the Device ID is typically related to the Google Play Services and is most c 3 min read How to Get Screen Width and Height in Android? Android applications are being developed for different device orientations to support a huge range of devices. So that users with different device size configurations can use the application. Many applications need to get the height and width of the device screen to create UI. In this article, we wi 3 min read How to Generate QR Code in Android? QR codes are used in many apps to display data in machine-readable form. These codes are used to represent data in a secure manner that is readable only by machines and not by humans. We have seen many apps that provide QR codes and we can scan those QR codes with our mobile device. In this article, 4 min read How to Connect to Android with ADB over TCP? In this article, we will discuss how we connect the Android Debug Bridge (ADB) over TCP. ADB is used to communicate with the device. It provides access to a Unix shell that you can use to run a variety of commands on a device. It has mainly three components: Client: It is the user who sends the comm 2 min read How to Use Advertisement ID in Android? This article is about adding the newly introduced advertisement ID in android 13. Moving forward to further iterations of the android versions you will need to update this, otherwise, your app won't work with the new advertisement policy. What is an Advertisement and what it does do? At large, it is 4 min read Like