In this android programming source code example, we are going to get device information in Android.
You can copy and adopt this source code example to your android project without reinventing the wheel.
Below is a step by step source code to get device information in Android.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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=".DeviceFeatures.DeviceFeaturesActivity1"> <Button android:id="@+id/deviceInfoBtn" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorAccent" android:textColor="#ffffff" android:text="Get Device Info" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"/> <TextView android:id="@+id/infoDisplayTxt" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Info display here" android:layout_marginTop="10dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/deviceInfoBtn"/> </androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import com.bluapp.androidview2.R; public class DeviceFeaturesActivity1 extends AppCompatActivity { private Button deviceInfoBtn; private TextView infoDisplayTxt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_device_features1); deviceInfoBtn = (Button) findViewById(R.id.deviceInfoBtn); infoDisplayTxt = (TextView) findViewById(R.id.infoDisplayTxt); deviceInfoBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getDeviceInfo(); } }); } private void getDeviceInfo(){ infoDisplayTxt.setText("SERIAL: " + Build.SERIAL + "\n" + "MODEL: " + Build.MODEL + "\n" + "ID: " + Build.ID + "\n" + "Manufacture: " + Build.MANUFACTURER + "\n" + "Brand: " + Build.BRAND + "\n" + "Type: " + Build.TYPE + "\n" + "User: " + Build.USER + "\n" + "BASE: " + Build.VERSION_CODES.BASE + "\n" + "INCREMENTAL: " + Build.VERSION.INCREMENTAL + "\n" + "SDK: " + String.valueOf(Build.VERSION.SDK_INT) + "\n" + "BOARD: " + Build.BOARD + "\n" + "BRAND: " + Build.BRAND + "\n" + "HOST: " + Build.HOST + "\n" + "FINGERPRINT: "+Build.FINGERPRINT + "\n" + "Version Code: " + Build.VERSION.RELEASE); } }

If you have any question or suggestions kindly use the comment box or you can contact us directly through our contact page below.