How to Get Hardware and Software Information in Android || Android Hardware and Software Information - Android Tutorial World

Latest

Welcome to Android Tutorial World Blog, Here you can find all type of post or tutorial related to andorid app development in details.

Sunday, September 29, 2019

How to Get Hardware and Software Information in Android || Android Hardware and Software Information

How to Get Hardware and Software Information in Android




Hello Friends, Today we will teach you how to get hardware and software information in android.

Follow the Steps

Step 1. :- Open AndroidManifest.xml file and add two permissions
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Step 2. :- Now open your xml layout file and add TextView and Button for showing phone's hardware and software information.

activity_main.xml :-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:padding="16dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_centerHorizontal="true"
        android:id="@+id/textview"
        android:text="Hardware and Software Information"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/button"
        android:layout_below="@+id/textview"
        android:layout_marginBottom="10dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:id="@+id/txtViewInfo"/>

    </ScrollView>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Get Information"
        android:id="@+id/button"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

Design


We use two textview, one for heading ( Hardware and Software Information ) and second for showing mobile phone hardware and software information and one button, When user click on button second textview showing details about phone.
We use ScrollView for second textview for showing all the details correctly and user scroll textview easily when user's use small screen device.

Step 3. :- Now open MainActivity.java file and write some codes for showing device's hardware and software information.

first create public String screenSize() method for showing screen resolution.
 public String screenSize(){
        Display display = getWindowManager().getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);
        int width = point.x;
        int height = point.y;

        return width + " x " + height;
    }

Now we need to create second method public String isMobileNetworkAvaiable for checking network availability and network status.
 public String isMobileNetworkAvailable(){
        ConnectivityManager manager = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if (networkInfo != null && networkInfo.isConnected()){
            return "Connected";
        }else {
            return "Disconnected";
        }
    }

Now create another method for checking wifi availability in the device and wifi status.
 public String bluetoothConnection(){
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (bluetoothAdapter == null){
            return "Not Supported";
        }else if (!bluetoothAdapter.isEnabled()){
            return "Disabled";
        }else {
            return "Enabled";
        }
    }

Full Code :-
package com.akshayarora.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.graphics.Point;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView infoTextView;
    private Button btn;

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

        infoTextView = (TextView)findViewById(R.id.txtViewInfo);
        btn = (Button)findViewById(R.id.button);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("MODEL : " + Build.MODEL + "\n");
                stringBuilder.append("SERIAL : " + Build.SERIAL + "\n");
                stringBuilder.append("ID : " + Build.ID + "\n");
                stringBuilder.append("MANUFACTURER : " + Build.MANUFACTURER + "\n");
                stringBuilder.append("BRAND : " + Build.BRAND + "\n");
                stringBuilder.append("TYPE : " + Build.TYPE + "\n");
                stringBuilder.append("USER : " + Build.USER + "\n");
                stringBuilder.append("BASE : " + Build.VERSION_CODES.BASE + "\n");
                stringBuilder.append("INCREMENTAL : " + Build.VERSION.INCREMENTAL + "\n");
                stringBuilder.append("SDK : " + Build.VERSION.SDK_INT + "\n");
                stringBuilder.append("BOARD : " + Build.BOARD + "\n");
                stringBuilder.append("HOST : " + Build.HOST + "\n");
                stringBuilder.append("FINGERPRINT : " + Build.FINGERPRINT + "\n");
                stringBuilder.append("VERSION RELEASE (Android Version) : " + Build.VERSION.RELEASE + "\n");
                stringBuilder.append("RESOLUTION : " + screenSize()+ "\n");
                stringBuilder.append("MOBILE NETWORK STATUS : " + isMobileNetworkAvailable() + "\n");
                stringBuilder.append("WIFI STATUS : " + isWifiNetworkAvailable() + "\n");
                stringBuilder.append("BLUETOOTH STATUS : " + bluetoothConnection());

                infoTextView.setText(stringBuilder);
        }
        });
    }

    public String screenSize(){
        Display display = getWindowManager().getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);
        int width = point.x;
        int height = point.y;

        return width + " x " + height;
    }
   
    public String isMobileNetworkAvailable(){
        ConnectivityManager manager = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if (networkInfo != null && networkInfo.isConnected()){
            return "Connected";
        }else {
            return "Disconnected";
        }
    }

    public String isWifiNetworkAvailable(){
        ConnectivityManager manager = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        if (networkInfo != null  && networkInfo.isConnected()){
            return "Connected";
        }else {
            return "Disconnected";
        }
    }

    public String bluetoothConnection(){
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (bluetoothAdapter == null){
            return "Not Supported";
        }else if (!bluetoothAdapter.isEnabled()){
            return "Disabled";
        }else {
            return "Enabled";
        }
    }
}

We use StringBuilder for showing all the text data in the textview.
StringBuilder use for showing different type of data in one textview / one object.
StringBuilder object with append use for add data in the string and we can use all the data in one textview, in one place easily.
After set all the data in StringBuilder we set it on textview for showing all the information of device.

After doing all the work run the project and check output

Output :-



Some information is not showing because we are using android emulator for out tutorials you can use this project and run the app on your real device and check the output

We are check it on real device Redmi 6



Enjoy !

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.