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
- Personalization: customizing app experiences with friendly names.
- Debugging: identifying user devices and reproducing errors more easily.
- 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:
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:
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:
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
| Method | Strengths | Weaknesses |
Using Build Class | Simple API calls, no permissions needed | Limited to predefined properties |
Settings.System Provider | Retrieves user-set, personalized names | Requires additional permissions, might not be reliable |
| Reflection and System Properties | Access more properties, flexibility | Requires deeper knowledge of Android internals |
Related reading
- Get Android Phone Model programmatically , How to get Device name and model programmatically in android?
- Get application version programmatically in android
- Get Bitmap attached to ImageView
- Get boolean from database using Android and SQLite
- Get button click inside UITableViewCell
- Get class name of object as string in Swift
- Get content uri from file path in android
- Get currency symbols from currency code with swift
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo 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 courseData 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.