public class DeviceName
extends java.lang.Object
Get the consumer friendly name of an Android device.
On many popular devices the market name of the device is not available. For example, on the
Samsung Galaxy S6 the value of Build.MODEL could be "SM-G920F", "SM-G920I", "SM-G920W8",
etc.
See the usages below to get the consumer friends name of a device:
Get the name of the current device:
String deviceName = DeviceName.getDeviceName();
The above code will get the correct device name for the top 600 Android devices. If the device is unrecognized, then Build.MODEL is returned.
Get the name of a device using the device's codename:
// Retruns "Moto X Style"
DeviceName.getDeviceName("clark", "Unknown device");
Get information about the device:
DeviceName.with(context).request(new DeviceName.Callback() {
@Override public void onFinished(DeviceName.DeviceInfo info, Exception error) {
String manufacturer = info.manufacturer; // "Samsung"
String name = info.marketName; // "Galaxy S6 Edge"
String model = info.model; // "SM-G925I"
String codename = info.codename; // "zerolte"
String deviceName = info.getName(); // "Galaxy S6 Edge"
// FYI: We are on the UI thread.
}
});
The above code loads JSON from a generated list of device names based on Google's maintained list. It will be up-to-date with Google's supported device list so that you will get the correct name for new or unknown devices. This supports over 10,000 devices.
This will only make a network call once. The value is saved to SharedPreferences for future calls.
| Modifier and Type | Class and Description |
|---|---|
static interface |
DeviceName.Callback
Callback which is invoked when the
DeviceName.DeviceInfo is finished loading. |
static class |
DeviceName.DeviceInfo
Device information based on
Google's maintained list.
|
static class |
DeviceName.Request |
| Constructor and Description |
|---|
DeviceName() |
| Modifier and Type | Method and Description |
|---|---|
static DeviceName.DeviceInfo |
getDeviceInfo(android.content.Context context)
Get the
DeviceName.DeviceInfo for the current device. |
static java.lang.String |
getDeviceName()
Get the consumer friendly name of the device.
|
static java.lang.String |
getDeviceName(java.lang.String codename,
java.lang.String fallback)
Get the consumer friendly name of a device.
|
static java.lang.String |
getDeviceName(java.lang.String codename,
java.lang.String model,
java.lang.String fallback)
Get the consumer friendly name of a device.
|
static DeviceName.Request |
with(android.content.Context context)
Create a new request to get information about a device.
|
public static DeviceName.Request with(android.content.Context context)
context - the application contextpublic static java.lang.String getDeviceName()
getDeviceName(String, String)public static java.lang.String getDeviceName(java.lang.String codename,
java.lang.String fallback)
codename - the value of the system property "ro.product.device" (Build.DEVICE)
or
the value of the system property "ro.product.model" (Build.MODEL)fallback - the fallback name if the device is unknown. Usually the value of the system property
"ro.product.model" (Build.MODEL)fallback if the device is unknown.public static java.lang.String getDeviceName(java.lang.String codename,
java.lang.String model,
java.lang.String fallback)
codename - the value of the system property "ro.product.device" (Build.DEVICE).model - the value of the system property "ro.product.model" (Build.MODEL).fallback - the fallback name if the device is unknown. Usually the value of the system property
"ro.product.model" (Build.MODEL)fallback if the device is unknown.public static DeviceName.DeviceInfo getDeviceInfo(android.content.Context context)
DeviceName.DeviceInfo for the current device. Do not run on the UI thread, as this may
download JSON to retrieve the DeviceName.DeviceInfo. JSON is only downloaded once and then
stored to SharedPreferences.context - the application context.DeviceName.DeviceInfo for the current device.