How to Get Android Device Information

Sometimes we need the user hardware information to keep track what type of user android device using our application. In the Android SDK, there have problem some classes to get the android hardware information in the application. The information that we can get are Android version, Android Model, Sim card telco, IMEI and more. Every device have different attributes and we need to know about it. In this tutorial, I will teach you how to get android device information in your new project.

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “DeviceInfoExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Add recyclerview dependency

I add this dependency in the build.gradle(Module:app), so i can use recyclerview to display the list of device information.

Add new permissions

Go to your AndroidManifest file and add 3 new permissions which are READ_PHONE_STATE, ACCESS_NETWORK_STATE and ACCESS_WIFI_STATE.

Create a new Model Class

Right click your project name and create a new class for device model. Copy the source code in the below.

Create a new Adapter class

Adapter is the middle man of the view and model, the adapter will pass the model and display it in the activity view.

Add a new xml layout

Create a new xml layout for the recyclerview item row. The xml name “row_item”.

Edit activity_main.xml layout

Open your activity_main and change to the following layout.

Edit class

Change this class source code, and it will display all the device information in your activity. Note : Android M and above should allow the permissions access for the device infomation.

Run your Project

Lastly, you can now try to run and view the device information on your mobile device.

(How to Get Android Device Information)

Source Code

(Visited 758 times, 1 visits today)

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

Leave a Reply

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