Android
Device Name
Android Development
Tech Guide
Smartphone Settings

How to get the device name in Android

Codemia Knowledge Hub ·

For the device's model name, combine Build.MANUFACTURER and Build.MODEL, which needs no permissions. For the name the user set in the device settings, read "device_name": the documented constant is Settings.Global.DEVICE_NAME (API 25 and later), while the Settings.System lookup shown below works only on some devices. A device name in Android can mean the manufacturer's name, the marketing name or a user-set custom name, and each comes from a different API.

Why apps read the device name

  1. Personalization: customizing app experiences with friendly names.
  2. Debugging: identifying user devices and reproducing errors more easily.
  3. Tracking and analytics: better insight into user demographics.

Methods to get the device name

1. The Build class

Build exposes information about the current build, including brand, manufacturer and model:

java
String manufacturer = android.os.Build.MANUFACTURER;
String model = android.os.Build.MODEL;
String deviceName = manufacturer + " " + model;
  • Build.MANUFACTURER: the product manufacturer.
  • Build.MODEL: the end-user-visible name of the product.

2. The Settings.System content provider

This reads the user-configurable device name, typically set in the device's settings:

java
import android.provider.Settings;

String deviceName = Settings.System.getString(getContentResolver(), "device_name");

Note: in some device configurations this requires the READ_PHONE_STATE permission.

3. System properties via reflection

Reading system properties directly can give more detailed device information, but it takes deeper knowledge of the platform and may require reflection to access hidden APIs:

java
1import java.lang.reflect.Method;
2
3public String getDeviceName() {
4    String product = getSystemProperty("ro.product.name");
5    String manufacturer = getSystemProperty("ro.product.manufacturer");
6    return manufacturer + " " + product;
7}
8
9public String getSystemProperty(String propName) {
10    try {
11        Class<?> clazz = Class.forName("android.os.SystemProperties");
12        Method method = clazz.getMethod("get", String.class);
13        return (String) method.invoke(null, propName);
14    } catch (Exception e) {
15        e.printStackTrace();
16        return null;
17    }
18}

Permissions, privacy and compatibility

  • Permissions: some methods need explicit permissions, like READ_PHONE_STATE. Declare them and justify them to users.
  • Privacy: respect user privacy and do not use device information for unauthorized tracking.
  • Compatibility: test each method on several Android versions and handle deprecated APIs where necessary, since OS updates can change which methods and permissions are available.

Comparing the methods

MethodStrengthsWeaknesses
Using Build ClassSimple API calls, no permissions neededLimited to predefined properties
Settings.System ProviderRetrieves user-set, personalized namesRequires additional permissions, might not be reliable
Reflection and System PropertiesAccess more properties, flexibilityRequires deeper knowledge of Android internals

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms