How to get Android Device Hardware Information

How to get Android Device Hardware Information

In this tutorial we are going to learn how to get Android device hardware information. We will focus on the following hardware properties like Android SDK, Android Version, Android Brand, Manufacturer’s name and Android model.

This information is different from device to device. There are many other information you can get from a device but we will focus on the these five properties.

To create this application, we are going to use a ListView control with a custom adapter that will hold each item of information.

In order to understand what we are out to achieve, we are going to have a look at the screen shot of the application we will create below.


Before we start, it is important for you to understand the tools and environment I used in this application development tutorial. Feel free to use any tools you are familiar with.

Windows 7

Android Studio

Sony Xperia ZL

Min SDK 14

Target SDK 19

To create a new android application project, following the steps as stipulated below.

Go to File menu

Click on New menu

Click on Android Application

Enter Project name: AndroidDeviceHardware

Package: com.inducesmile.androiddevicehardware

Keep other default selections.

Continue to click on next button until Finish button is active, then click on Finish Button.

If you are using Android Studio as your choice IDE, the new project will create a default file and its corresponding layout file. Open the two files because we are going to

make use of them.

Now, open the activity_main.xml layout, we are going to add a ListView control. The code snippet layout code is shown below.

<RelativeLayout xmlns:android=""

        android:scrollbars="none" />


As you can see, the layout code is very simple and does not even need explanation. Now that will have done with the layout file, We will head over on the file to create the corresponding code that will retrieve the device information.

In the file, we will get the handle for the ListView component. We will call the setAdapter() method of the ListView instance and the Adapter instance will be passed as parameter.

Since we haven’t created the Adapter class, I think this is the best time to create the class. The Adapter class will inflate a layout file that will house two TextView controls. The code snippet is as shown.


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;


public class HardwareAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;
    private List<HardwareObject> listStorage;

    public HardwareAdapter(Context context, List<HardwareObject> customizedListView) {
        layoutInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        listStorage = customizedListView;

    public int getCount() {
        return listStorage.size();

    public Object getItem(int position) {
        return position;

    public long getItemId(int position) {
        return position;

    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder listViewHolder;
        if(convertView == null){
            listViewHolder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.hardware_cardview, parent, false);

            listViewHolder.hardware = (TextView)convertView.findViewById(;
            listViewHolder.hardwareMeaning = (TextView)convertView.findViewById(;
            listViewHolder = (ViewHolder)convertView.getTag();

        return convertView;

    static class ViewHolder{

        TextView hardware;
        TextView hardwareMeaning;

You can see that in the getView(int position, View convertView, ViewGroup parent) method of the Adapter class, a layout file was inflate. The Adapter class also contains an inner class called ViewHolder which holds the instances of the TextView components.

The code for the inflated layout file – hardware_cardview.xml is shown below.

<?xml version="1.0" encoding="utf-8"?>
< xmlns:android=""



            android:layout_alignParentEnd="true" />



Bear in mind that this layout file uses a CardView as the GroupView in the layout. In other to use a CardView component in your application, we are going to add the following line of code in our project build.gradle file.

compile ''

What it does is it fetch the library and add it in our project so that we can have access to it and its numerous properties. As you can see, it is two TextViews arrange side by side to each other.

Finally, we will look at our file once again since we have explain and code all the different parts we need for the application.

The code snippet for our file as shown below.

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {
    public View onCreate(Bundle savedInstanceState){
        List<HardwareObject> mObject = getHardwareInformation();
        ListView androidList = (ListView)view.findViewById(;
        HardwareAdapter hAdapter = new HardwareAdapter(getActivity(), mObject);
        return view;
    private List<HardwareObject> getHardwareInformation(){
        List<HardwareObject> hardware = new ArrayList<HardwareObject>();
        String[] mAndroid = getAndroidHardWare();
        hardware.add(new HardwareObject("Android SDK", mAndroid[0]));
        hardware.add(new HardwareObject("Android Version", mAndroid[1]));
        hardware.add(new HardwareObject("Android Brand", mAndroid[2]));
        hardware.add(new HardwareObject("Manufacturer", mAndroid[3]));
        hardware.add(new HardwareObject("Android Model", mAndroid[4]));
        return hardware;
    private String[] getAndroidHardWare(){
        String androidSDK = String.valueOf(android.os.Build.VERSION.SDK_INT);
        String androidVersion = android.os.Build.VERSION.RELEASE;
        String androidBrand = android.os.Build.BRAND;
        String androidManufacturer = android.os.Build.MANUFACTURER;
        String androidModel = android.os.Build.MODEL;
        return new String[]{androidSDK, androidVersion, androidBrand, androidManufacturer, androidModel};

Apart from the Adapter class that we discuss previously, there are two other method we created in the class – getHardwareInformation() and getAndroidHardWare()

When you look at the getHardwareIndformation() method, you will see that we made use of an entity object class called HardwareObject. This instance of the class wraps two corresponding TextView and it is added in a List object.

In the onCreate(Bundle savedInstanceState) method of the class, the getHardwareInformation() method returns the values that is passed as a parameter in the Adapter class.

Now, when you run your application you will see the interface that looks similar to the sample that was shown earlier on.

You can download the code for this tutorial below. If you are having hard time downloading the tutorials, kindly contact me.

Remember to subscribe with your email so that you will be among the first to receive our new post once it is published.

If you like this tutorial, please kindly download my new android app in Google play store by clicking the image below

One Response

Add a Comment