Android device details programmatically

How Get Device Details in android

How Get Device Details in android

Hi friends in today tutorial we are going to learn how retrieve android device ID and android version and company model name of the device programmatically using android ‘TelephonyManager’ class. It’s a simple code. Use shortcode below. Before execute this code below add permission ‘READ_PHONE_STATE’.

Read How add permission in manifest file.

Permission Need:-

 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Short Code:-
1. For Device ID:-
public static String getDeviceId(Context ctx)
{

@SuppressWarnings("static-access")
TelephonyManager telephonyManager = (TelephonyManager)ctx.getSystemService(ctx.TELEPHONY_SERVICE);
return telephonyManager.getDeviceId();
}

2. For Device Model:-

public static String getDeviceModel(Context ctx)
{
return android.os.Build.MODEL;

}

3. For Device Android Version:-

public static String getDeviceVersion(Context ctx)
{
return android.os.Build.VERSION.RELEASE;

}

 

Now Check Full Source Code

DeviceIdActivity.java


 

package com.androidfromhome.deviseid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class DeviceIdActivity extends Activity {

    private TextView tv_id;
    private TextView tv_android_ver;
    private TextView tv_build_ver;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_devise_id);
        
        
        tv_id=(TextView)findViewById(R.id.tv_id);
        tv_android_ver=(TextView)findViewById(R.id.tv_android_ver);
        tv_build_ver=(TextView)findViewById(R.id.tv_build_ver);
        
        
        tv_id.setText("Device Id "+Util.getDeviceId(DeviceIdActivity.this));
        
        tv_android_ver.setText("Android Version "+Util.getDeviceVersion(DeviceIdActivity.this));
        
        tv_build_ver.setText("Device Model "+Util.getDeviceModel(DeviceIdActivity.this));
               
    }
}

 


 

 

Util.java


 

package com.androidfromhome.deviseid;

import android.content.Context;
import android.telephony.TelephonyManager;

public class Util {
    
    public static String getDeviceId(Context ctx)
    {
        
        @SuppressWarnings("static-access")
        TelephonyManager telephonyManager = (TelephonyManager)ctx.getSystemService(ctx.TELEPHONY_SERVICE);
        return telephonyManager.getDeviceId();
    }
    
    public static String getDeviceModel(Context ctx)
    {
        return android.os.Build.MODEL;
        
    }
    
    
    public static String getDeviceVersion(Context ctx)
    {
        return android.os.Build.VERSION.RELEASE;
        
    }   
}

 


 

 

xml source code

activity_devise_id.xml


 

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/LinearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#A758AB"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="15dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:text="Android From Home"
            android:textColor="#ffffff"
            android:textSize="22dp"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tv_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:textColor="#000000"
            android:textSize="18dp" />

        <TextView
            android:id="@+id/tv_android_ver"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:textColor="#000000"
            android:textSize="18dp" />

        <TextView
            android:id="@+id/tv_build_ver"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:textColor="#000000"
            android:textSize="18dp" />

        <TextView
            android:id="@+id/tv_version_code"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:textColor="#000000"
            android:textSize="18dp" />

    </LinearLayout>

</LinearLayout>


 

 

Download Full Source Code

 

Related Post:-

Expandable ListView in android example

how to get the call log details in android

How Retrieve contact list in android

Custom Toast example in android example

 

Leave a Reply

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

Get Widget