DEV Community

Dhruv Joshi
Dhruv Joshi

Posted on • Updated on

🔥(Best Guide) How to code a Android app that shows phone's statistics and other hardware info?

To create an Android app that displays phone statistics and other hardware information, you will need to use the Android SDK and programming language such as Java or Kotlin. Here is a sample code snippet that demonstrates how to access and display some of this information:

// Get the phone's model number
String model = Build.MODEL;

// Get the phone's manufacturer
String manufacturer = Build.MANUFACTURER;

// Get the phone's battery level
BatteryManager bm = (BatteryManager)getSystemService(BATTERY_SERVICE);
int batteryLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);

// Get the phone's storage capacity
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSizeLong();
long totalBlocks = stat.getBlockCountLong();
long totalSpace = totalBlocks * blockSize;

// Display the information in a TextView
TextView tv = findViewById(R.id.text_view);
String text = "Model: " + model + "\n"
        + "Manufacturer: " + manufacturer + "\n"
        + "Battery Level: " + batteryLevel + "%\n"
        + "Total Storage: " + totalSpace + " bytes";
tv.setText(text);

Enter fullscreen mode Exit fullscreen mode

This code will retrieve the phone's model number, manufacturer, battery level, and total storage capacity, and display them in a TextView.

To use this code in your app, you will need to add the necessary import statements at the top of your file and include the TextView in your layout XML file. You will also need to add the BATTERY_SERVICE permission to your app's manifest file.

I hope this helps! Let me know if you have any questions or need more guidance or you can reach me here.

Top comments (0)