426

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

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Andrea Baccega
  • 27,211
  • 13
  • 45
  • 46

16 Answers16

489

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

Joshua
  • 1,167
  • 1
  • 14
  • 32
Volo
  • 28,673
  • 12
  • 97
  • 125
  • It there a list somewhere that hold all possible answer you can get out of the phone. Say if you need to redirect a user on how to install something on a specific phone type or sell something to a specific model. – evilfish Sep 02 '14 at 11:42
  • 10
    @evilfish Try this list from Google: https://support.google.com/googleplay/answer/1727131 – Volo Sep 03 '14 at 08:28
  • Works perfectly on watch because I needed it for Android Wear. – Wahib Ul Haq Mar 18 '15 at 17:23
  • 3
    I don't understand why Google doesn't include something like Build.MARKET_NAME – Tyler Aug 24 '21 at 13:56
369

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)

Community
  • 1
  • 1
Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
  • 19
    Thanks Jared. I needed this today but for Xamarin.Android so translated your file to C#. If somebody else needs it, you can find it here. https://gist.github.com/mohibsheth/5e1b361ae49c257b8caf – Mohib Sheth Jan 21 '15 at 13:03
  • 1
    Is there a way to get the "human readable" devicename like "Xperia Z3" or "Galaxy S3" without this Devices class ? I don`t like to use a static list of all devices to be sure even all future devices will be supported. – Radon8472 Mar 05 '15 at 07:41
  • 1
    @Radon8472 Have you tried the static factory method above named `getDeviceName()`? If that doesn't give you the results you are looking for there isn't a better solution that I know of. – Jared Rummler Mar 05 '15 at 10:14
  • @Jared: I already have a devicename like the results of 'getDeviceName()' but I like to display the name wich endusers know from their handy stores :( – Radon8472 Mar 14 '15 at 17:58
  • In the above Github project used the public URL="https://storage.googleapis.com/play_public...." is it have trusted server certificate ..else these days (April 2021) Google will not allow app be distributed on Play Store if they detect insecure hostname verifier..@Jared Rummer – ShriKant A May 17 '21 at 08:32
118

Yes: Build.MODEL.

Mirko N.
  • 10,537
  • 6
  • 38
  • 37
  • 1
    It always gives me "Android SDK built for x86" when I try it with emulator. Cannot able to get the model name specifically in emulator run with different model name. – Swathi Dec 16 '18 at 06:56
  • 2
    Yes, that's the model of the emulator. Note that it even uses a similar name for the internal storage. – Clement Osei Tano Feb 05 '19 at 14:29
42

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")
ruX
  • 7,224
  • 3
  • 39
  • 33
35

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
Falcon165o
  • 2,875
  • 1
  • 20
  • 31
  • 10
    I've found that `String name = Build.MANUFACTURER + " - " + Build.MODEL` to be the most useful combination. Build.PRODUCT sometimes uses an unexpected name. For example, on the Galaxy Nexus, it returns "takgu". Build.MODEL, on the other hand, is the user-facing value displayed under Settings->About Phone->Model number. – Mike Ortiz Aug 30 '12 at 19:20
  • 1
    A lot of it depends on the manufacturer; HTC devices (Evo 4G, 4G LTE, 3D and Slide) use what I stated above. – Falcon165o Aug 31 '12 at 13:35
  • AXON 7 mini is in list. Yet where is regularly sized AXON? – Serge Jul 06 '17 at 14:30
17
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);
    }
Ajay Pandya
  • 2,417
  • 4
  • 29
  • 65
12

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)
CoolMind
  • 26,736
  • 15
  • 188
  • 224
Sean
  • 5,176
  • 2
  • 34
  • 50
  • 1
    `capitalize` is now deprecated. instead use this `.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }` – Krrishnaaaa Oct 13 '21 at 15:22
9

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

Edwin Evans
  • 2,726
  • 5
  • 34
  • 47
8

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;
silkfire
  • 24,585
  • 15
  • 82
  • 105
8
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
majurageerthan
  • 2,169
  • 3
  • 17
  • 30
7

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
RamakanthReddy
  • 121
  • 2
  • 4
3

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
V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
3

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)
    }
}
  • I've posted a shorter version with Kotlin's `capitalize ` https://stackoverflow.com/a/59158474/1446466 – Sean Dec 03 '19 at 13:45
1

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();
    }
}
Xjasz
  • 1,238
  • 1
  • 9
  • 21
0

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;
}
Sridhar Nalam
  • 527
  • 8
  • 9
-3

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

public String phoneModel() {

    return Build.MODEL;
}
Quantum4U
  • 35
  • 4