How to Fetch Device ID in Android Programmatically? Last Updated : 30 Aug, 2022 Comments Improve Suggest changes Like Article Like Report 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 commonly used in ad personalization. These IDs are collected and are used for displaying particular types of ads. This type is calculated upon user search and navigation tracking. One can root the device to erase the Device ID and avoid tracking and ad personalization. In this article, we will show you how you could fetch the Device ID of your Android device. Follow the below steps once the IDE is ready. Step By Step ImplementationStep 1: Create a New Project in Android StudioTo create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. The code for that has been given in both Java and Kotlin Programming Language for Android. Step 2: Working with the XML FilesNext, go to the activity_main.xml file, which represents the UI of the project. Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail. XML <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <!-- This TextView will display the Device ID --> <TextView android:id="@+id/textview_1" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> Step 3: Working with the MainActivity FileGo to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail. Kotlin import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.provider.Settings import android.widget.TextView class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Declaring and initializing a constant for // the TextView from the layout // file (activity_main.xml) val mTextView1 = findViewById<TextView>(R.id.textview_1) // Fetching Android ID and storing it into a constant val mId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) // Displaying the Android ID into the TextView mTextView1.text = mId } } Java import android.os.Bundle; import android.provider.Settings; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Declaring and initializing a constant for the TextView from the layout file (activity_main.xml) TextView mTextView1 = findViewById(R.id.textview_1); // Fetching Android ID and storing it into a constant String mId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); // Displaying the Android ID into the TextView mTextView1.setText(mId); } } Output:You would see that when the app launches, the device ID is fetched and displayed in TextView. Comment More infoAdvertise with us Next Article How to Fetch Device ID in Android Programmatically? aashaypawar Follow Improve Article Tags : Java Kotlin Android Practice Tags : Java Similar Reads 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 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 Vibrate a Device Programmatically in Android? Hepatic feedback are also considered when it comes to user experience. So in this discussion, it's been discussed various types of haptics or the types of vibration of the device. For example, click haptics or long-press button haptics. There five different types of vibration modes in haptic feedbac 7 min read How to Detect Tablet or Phone in Android Programmatically? A Mobile is a portable electronic device that allows you to make calls, send messages, and access the internet, among other functions. A tablet is a mobile computing device with a touchscreen display and typically a larger screen size than a smartphone. Both devices are designed to be portable and a 3 min read How to Get RAM Memory in Android Programmatically? RAM (Random Access Memory) of a device is a system that is used to store data or information for immediate use by any application that runs on the device. Every electronic device that runs a program as a part of its application has some amount of RAM associated with it. Mobile devices nowadays come 3 min read How to Fetch Currently Running Tasks in Android Programmatically? Android devices run several tasks in the background for providing a seamless experience to the users. Importantly, tracking background and foreground usages is important as it directly impacts the battery life and static memory, i.e. RAM. One can enable the developer option in the settings to track 2 min read How to Check GPS is On or Off in Android Programmatically? GPS (Global Positioning System) is a satellite-based navigation system that accommodates radio signals between satellite and device to process the device's location in the form of coordinates. GPS gives latitude and longitude values of the device. Recent mobile phones are equipped with GPS modules t 2 min read How to Display Bluetooth Paired Devices Programmatically in Android? Bluetooth's technology is a high-speed, low-powered wireless technology link designed to connect devices such as phones or other portable equipment. It has a specification (IEEE 802.15.1) for low-power radio communications to link computers, phones, and other network devices over a short distance in 5 min read How to Find Out Carrier's Name in Android Programmatically? In this article we will see how to retrieve the carrier name on Android device. This information can be useful for applications that need to provide specific functionality based on the user's cellular network provider. A sample video is given below to get an idea about what we are going to do in thi 3 min read How to Detect Touch Event on Screen Programmatically in Android? Detecting a touch confirms that the screen is fully functional. Responding to touch is something that a developer deals with. As Android devices have a touch-based input, things are programmed upon application of touch. For explicitly calling methods within the application, a touch action must be re 5 min read Like