Sunday, 1 September 2013

Get Device ID Demo

Demo:

1) MainActivity.java:
 
package com.venky.getdeviceiddemo; 
import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.widget.TextView;

public class MainActivity extends Activity {

       TextView tv = null;

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

             tv = (TextView) findViewById(R.id.tv1);

             String deviceId = Secure.getString(getContentResolver(),
                           Secure.ANDROID_ID);
             tv.setText("Your Device ID\n" + deviceId);
       }
}

2) 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"
    android:background="#5F04B4"
    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=".MainActivity" >

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        android:textColor="#ffffff"
        android:textSize="20dp"
        android:textStyle="bold" />

</RelativeLayout>

3) Download this Project Click Here

No comments:

Post a Comment