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

16

430

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

Behl answered 3/1, 2010 at 16:19 Comment(1)
I don't understand why Google doesn't include something like Build.MARKET_NAMESeddon
F
371

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)

Flash answered 8/1, 2015 at 9:37 Comment(5)
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. gist.github.com/mohibsheth/5e1b361ae49c257b8cafConsumedly
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.Stadtholder
@Stadtholder 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.Flash
@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 :(Stadtholder
In the above Github project used the public URL="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 RummerFaris
H
495

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

Hawker answered 3/10, 2012 at 11:23 Comment(4)
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.Calctufa
@Calctufa Try this list from Google: support.google.com/googleplay/answer/1727131Hawker
Works perfectly on watch because I needed it for Android Wear.Endblown
I don't understand why Google doesn't include something like Build.MARKET_NAMESeddon
F
371

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)

Flash answered 8/1, 2015 at 9:37 Comment(5)
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. gist.github.com/mohibsheth/5e1b361ae49c257b8cafConsumedly
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.Stadtholder
@Stadtholder 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.Flash
@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 :(Stadtholder
In the above Github project used the public URL="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 RummerFaris
C
120

Yes: Build.MODEL.

Catheryncatheter answered 3/1, 2010 at 16:23 Comment(2)
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.Cooee
Yes, that's the model of the emulator. Note that it even uses a similar name for the internal storage.Reseau
M
45

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")
Mahayana answered 16/8, 2016 at 12:28 Comment(0)
H
37

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
Horrorstruck answered 6/3, 2012 at 18:50 Comment(3)
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.Salicin
A lot of it depends on the manufacturer; HTC devices (Evo 4G, 4G LTE, 3D and Slide) use what I stated above.Horrorstruck
AXON 7 mini is in list. Yet where is regularly sized AXON?Hypercorrection
C
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);
    }
Caesarea answered 3/9, 2014 at 11:9 Comment(0)
O
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)
Ophthalmologist answered 3/12, 2019 at 13:42 Comment(1)
capitalize is now deprecated. instead use this .replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }Cyclostyle
S
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...

Strom answered 12/9, 2014 at 17:36 Comment(1)
AXON 7 mini is in the list. Yet where is the regularly sized AXON?Hypercorrection
D
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;
Dragone answered 21/5, 2014 at 11:2 Comment(0)
M
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
Multivibrator answered 10/1, 2020 at 4:28 Comment(0)
F
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
Frontality answered 9/1, 2013 at 5:29 Comment(0)
U
4

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
Ulmaceous answered 22/2, 2017 at 11:22 Comment(0)
B
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)
    }
}
Bitternut answered 28/3, 2018 at 13:36 Comment(1)
I've posted a shorter version with Kotlin's capitalize https://mcmap.net/q/11840/-get-android-phone-model-programmatically-how-to-get-device-name-and-model-programmatically-in-androidOphthalmologist
H
2

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();
    }
}
Hamilton answered 10/9, 2016 at 6:1 Comment(0)
R
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;
}
Regnal answered 16/1, 2018 at 13:47 Comment(1)
THANK YOU!! Note that permission BLUETOOTH is required for this to work.Distributee
T
-3

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

public String phoneModel() {

    return Build.MODEL;
}
Tiliaceous answered 18/1, 2018 at 8:18 Comment(1)
This answer does not improve on any of the other answers that said the same thing, and were left here a year ago.Heaviness

© 2022 - 2024 — McMap. All rights reserved.