[android] Get Android Phone Model programmatically

I would like to know if there is a way for reading the Phone Model programmatically in Android.

I would like to get a string like HTC Dream, Milestone, Sapphire or whatever...

This question is related to android android-hardware

The answer is


Changed Idolons code a little. This will capitalize words when getting the device model.

public static String getDeviceName() {
    final String manufacturer = Build.MANUFACTURER, model = Build.MODEL;
    return model.startsWith(manufacturer) ? capitalizePhrase(model) : capitalizePhrase(manufacturer) + " " + model;
}

private static String capitalizePhrase(String s) {
    if (s == null || s.length() == 0)
        return s;
    else {
        StringBuilder phrase = new StringBuilder();
        boolean next = true;
        for (char c : s.toCharArray()) {
            if (next && Character.isLetter(c) || Character.isWhitespace(c))
                next = Character.isWhitespace(c = Character.toUpperCase(c));
            phrase.append(c);
        }
        return phrase.toString();
    }
}

you can use the following code for getting the brand name and brand model of the device.

 String brand = Build.BRAND; // for getting BrandName
 String model = Build.MODEL; // for getting Model of the device

I use the following code to get the full device name. It gets model and manufacturer strings and concatenates them unless model string already contains manufacturer name (on some phones it does):

public String getDeviceName() {
    String manufacturer = Build.MANUFACTURER;
    String model = Build.MODEL;
    if (model.toLowerCase().startsWith(manufacturer.toLowerCase())) {
        return capitalize(model);
    } else {
        return capitalize(manufacturer) + " " + model;
    }
}


private String capitalize(String s) {
    if (s == null || s.length() == 0) {
        return "";
    }
    char first = s.charAt(0);
    if (Character.isUpperCase(first)) {
        return s;
    } else {
        return Character.toUpperCase(first) + s.substring(1);
    }
} 

 

Here are a few examples of device names I got from the users:

Samsung GT-S5830L
Motorola MB860
Sony Ericsson LT18i
LGE LG-P500
HTC Desire V
HTC Wildfire S A510e


Actually that is not 100% correct. That can give you Model (sometime numbers).
Will get you the Manufacturer of the phone (HTC portion of your request):

 Build.MANUFACTURER

For a product name:

 Build.PRODUCT

Yes: Build.MODEL.


For whom who looking for full list of properties of Build here is an example for Sony Z1 Compact:

Build.BOARD = MSM8974
Build.BOOTLOADER = s1
Build.BRAND = Sony
Build.CPU_ABI = armeabi-v7a
Build.CPU_ABI2 = armeabi
Build.DEVICE = D5503
Build.DISPLAY = 14.6.A.1.236
Build.FINGERPRINT = Sony/D5503/D5503:5.1.1/14.6.A.1.236/2031203XXX:user/release-keys
Build.HARDWARE = qcom
Build.HOST = BuildHost
Build.ID = 14.6.A.1.236
Build.IS_DEBUGGABLE = false
Build.MANUFACTURER = Sony
Build.MODEL = D5503
Build.PRODUCT = D5503
Build.RADIO = unknown
Build.SERIAL = CB5A1YGVMT
Build.SUPPORTED_32_BIT_ABIS = [Ljava.lang.String;@3dd90541
Build.SUPPORTED_64_BIT_ABIS = [Ljava.lang.String;@1da4fc3
Build.SUPPORTED_ABIS = [Ljava.lang.String;@525f635
Build.TAGS = release-keys
Build.TIME = 144792559XXXX
Build.TYPE = user
Build.UNKNOWN = unknown
Build.USER = BuildUser

You can easily list those properties for your device in debug mode using "evaluate expression" dialog using kotlin:

android.os.Build::class.java.fields.map { "Build.${it.name} = ${it.get(it.name)}"}.joinToString("\n")

You can Try following function and its return your phoneModel name in string format.

public String phoneModel() {

    return Build.MODEL;
}

Build.DEVICE // The name of the industrial design.

Build.DEVICE Gives the human readable name for some devices than Build.MODEL

Build.DEVICE = OnePlus6
Build.MANUFACTURER = OnePlus
Build.MODEL = ONEPLUS A6003

The following strings are all of use when you want to retrieve manufacturer, name of the device, and/or the model:

String manufacturer = Build.MANUFACTURER;
String brand        = Build.BRAND;
String product      = Build.PRODUCT;
String model        = Build.MODEL;

Kotlin short version:

import android.os.Build.MANUFACTURER
import android.os.Build.MODEL

fun getDeviceName(): String =
    (if (MODEL.startsWith(MANUFACTURER, ignoreCase = true)) {
        MODEL
    } else {
        "$MANUFACTURER $MODEL"
    }).capitalize()

Apparently you need to use the list from Google at https://support.google.com/googleplay/answer/1727131

The APIs don't return anything I expect or anything in Settings. For my Motorola X this is what I get

   Build.MODEL = "XT1053"
   Build.BRAND = "motorola"
   Build.PRODUCT = "ghost"

Going to the page mentioned above "ghost" maps to Moto X. Seems like this could be a tad simpler...


You can get the phone device name from the

BluetoothAdapter

In case phone doesn't support Bluetooth, then you have to construct the device name from

android.os.Build class

Here is the sample code to get the phone device name.

public String getPhoneDeviceName() {  
        String name=null;
        // Try to take Bluetooth name
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter != null) {
            name = adapter.getName();
        }

        // If not found, use MODEL name
        if (TextUtils.isEmpty(name)) {
            String manufacturer = Build.MANUFACTURER;
            String model = Build.MODEL;
            if (model.startsWith(manufacturer)) {
                name = model;
            } else {
                name = manufacturer + " " + model;
            }
        } 
        return name;
}

Kotlin version

val Name: String by lazy {
    val manufacturer = Build.MANUFACTURER
    val model = Build.MODEL
    if (model.toLowerCase().startsWith(manufacturer.toLowerCase())) {
        capitalize(model)
    } else {
        capitalize(manufacturer) + " " + model
    }
}

private fun capitalize(s: String?): String {
    if (s == null || s.isEmpty()) {
        return ""
    }
    val first = s[0]
    return if (Character.isUpperCase(first)) {
        s
    } else {
        Character.toUpperCase(first) + s.substring(1)
    }
}

Here is my code , To get Manufacturer,Brand name,Os version and support API Level

String manufacturer = Build.MANUFACTURER;

String model = Build.MODEL + " " + android.os.Build.BRAND +" ("
           + android.os.Build.VERSION.RELEASE+")"
           + " API-" + android.os.Build.VERSION.SDK_INT;

if (model.startsWith(manufacturer)) {
    return capitalize(model);
} else {
    return capitalize(manufacturer) + " " + model;
}

Output:

System.out: button press on device name = Lava Alfa L iris(5.0) API-21

String deviceName = android.os.Build.MODEL; // returns model name 

String deviceManufacturer = android.os.Build.MANUFACTURER; // returns manufacturer

Use Following method to get model & manufacturer programmatically

  public String getDeviceName() {
        String manufacturer = Build.MANUFACTURER;
        String model = Build.MODEL;
        if (model.toLowerCase().startsWith(manufacturer.toLowerCase())) {
            return capitalize(model);
        } else {
            return capitalize(manufacturer) + " " + model;
        }
    }


    private String capitalize(String s) {
    if (s == null || s.length() == 0) {
        return "";
    }
    char first = s.charAt(0);
    if (Character.isUpperCase(first)) {
        return s;
    } else {
        return Character.toUpperCase(first) + s.substring(1);
    }