Get Android Phone Model programmatically , How to get Device name and model programmatically in android?

AndroidModelDeviceAndroid Hardware

Android Problem Overview


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...

Android Solutions


Solution 1 - Android

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
> …

Solution 2 - Android

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", or "SM-G920W8".

I created a small library that gets the market (consumer friendly) name of a device. It gets the correct name for over 10,000 devices and is constantly updated. If you wish to use my library click the link below:

AndroidDeviceNames Library on Github


If you do not want to use the library above, then this is the best solution for getting a consumer friendly device name:

/** Returns the consumer friendly device name */
public static String getDeviceName() {
  String manufacturer = Build.MANUFACTURER;
  String model = Build.MODEL;
  if (model.startsWith(manufacturer)) {
    return capitalize(model);
  }
  return capitalize(manufacturer) + " " + model;
}

private static String capitalize(String str) {
  if (TextUtils.isEmpty(str)) {
    return str;
  }
  char[] arr = str.toCharArray();
  boolean capitalizeNext = true;

  StringBuilder phrase = new StringBuilder();
  for (char c : arr) {
    if (capitalizeNext && Character.isLetter(c)) {
      phrase.append(Character.toUpperCase(c));
      capitalizeNext = false;
      continue;
    } else if (Character.isWhitespace(c)) {
      capitalizeNext = true;
    }
    phrase.append(c);
  }

  return phrase.toString();
}

Example from my Verizon HTC One M8:

// using method from above
System.out.println(getDeviceName());
// Using https://github.com/jaredrummler/AndroidDeviceNames
System.out.println(DeviceName.getDeviceName());

Result:

> HTC6525LVW > > HTC One (M8)

Solution 3 - Android

Solution 4 - Android

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")

Solution 5 - Android

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

Solution 6 - Android

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);
    }

Solution 7 - Android

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][1] mentioned above "ghost" maps to Moto X. Seems like this could be a tad simpler...

[1]: http://support.google.com/googleplay/answer/1727131 "page"

Solution 8 - Android

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(Locale.ROOT)

Solution 9 - Android

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;

Solution 10 - Android

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

Solution 11 - Android

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

Solution 12 - Android

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

Solution 13 - Android

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)
    }
}

Solution 14 - Android

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();
    }
}

Solution 15 - Android

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;
}

Solution 16 - Android

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

public String phoneModel() {

    return Build.MODEL;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndrea BaccegaView Question on Stackoverflow
Solution 1 - AndroidIdolonView Answer on Stackoverflow
Solution 2 - AndroidJared RummlerView Answer on Stackoverflow
Solution 3 - AndroidMirko N.View Answer on Stackoverflow
Solution 4 - AndroidruXView Answer on Stackoverflow
Solution 5 - AndroidFalcon165oView Answer on Stackoverflow
Solution 6 - AndroidAjay PandyaView Answer on Stackoverflow
Solution 7 - AndroidEdwin EvansView Answer on Stackoverflow
Solution 8 - AndroidSeanView Answer on Stackoverflow
Solution 9 - AndroidsilkfireView Answer on Stackoverflow
Solution 10 - AndroidRamakanthReddyView Answer on Stackoverflow
Solution 11 - AndroidmajurageerthanView Answer on Stackoverflow
Solution 12 - AndroidSaurabh GaddelpalliwarView Answer on Stackoverflow
Solution 13 - AndroidFrancisco PereiraView Answer on Stackoverflow
Solution 14 - AndroidXjaszView Answer on Stackoverflow
Solution 15 - AndroidSridhar NalamView Answer on Stackoverflow
Solution 16 - AndroidQuantum4UView Answer on Stackoverflow