Get android phone unique device id programmatically

Android get device id for push notification.

Accessing, searching your android mobile phone id is very easy with the use of android.provider.Settings.Secure package. Every android device on the whole world contain its unique id(  Identification signature ) which is different for each and every device. Android device id is mostly used for enabling push notification services on android mobile phone because push notification works on unique signature forms. So here is the complete step by step tutorial for find out and Get android phone unique device id programmatically and set it into textview.

android-project-download-code-button

How to Get android phone unique device id programmatically.

Code for MainActivity.java file.

 package com.uniquedeviceid_android_examples.com;

import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.widget.TextView;

public class MainActivity extends Activity {

 TextView DeviceID;
 String unique_id;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 DeviceID = (TextView)findViewById(R.id.textView1);
 
 unique_id = Secure.getString(getApplicationContext().getContentResolver(),Secure.ANDROID_ID);
 
 DeviceID.setText(unique_id);
 }
}

Code for activity_main.xml layout 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.uniquedeviceid_android_examples.com.MainActivity" >

 <TextView
 android:id="@+id/textView3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Your unique device id is :"
 android:textAppearance="?android:attr/textAppearanceLarge" />

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textView3"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="22dp"
 android:text="Large Text"
 android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Screenshot:

Get android phone unique device id programmatically

Click Here to download Get android phone unique device id programmatically project.

Leave a Reply

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