This example explains how to get android device unique ID. The device unique id is needed when we want user registration for specific device. This way we can achieve security.
Android Activity Layout (activity_main.xml)
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 (AndroidActivity.java)
package com.example.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
No comments:
Post a Comment