Tutorials Android Get Device ID Example in Android

Get Device ID Example in Android

This example explains how to get device unique id in android. The device unique id is needed when we want user registration for a specific device. This way we can achieve security. Most of the banking applications today are using such approach.

Android Activity Layout (activity_main.xml)

<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"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textColor="#cc0000"
        android:textSize="32sp" />

</RelativeLayout>

Android Activity (MainActivity.java)

package com.javatechig.getdeviceid;

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

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		//getting unique id for device
		String id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

		//displaying id in textview
		TextView tv = (TextView) findViewById(R.id.textView1);
		tv.setText(id);

	}

}

Output

Get Device ID Example in Android

Total
0
Shares
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Amr Essam
Amr Essam
7 years ago

that doesn’t work

vinod
vinod
6 years ago

it works fine!!!!!!!!!Thank you…..

Previous Post
Android Tutorials

Listing all SDCard Filenames with extensions in android

Next Post
Android Tutorials

Android Handler Example

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
2
0
Would love your thoughts, please comment.x
()
x