Obtener Modelo de Teléfono Android mediante programación


Me gustaría saber si hay una manera de leer el Modelo de Teléfono mediante programación en Android.

Me gustaría obtener una cadena como HTC Dream, Milestone, Sapphire o lo que sea...

Author: Cœur, 2010-01-03

14 answers

En muchos dispositivos populares, el nombre de mercado del dispositivo no está disponible. Por ejemplo, en el Samsung Galaxy S6 el valor de Build.MODEL podría ser "SM-G920F", "SM-G920I", o "SM-G920W8".

He creado una pequeña biblioteca que obtiene el nombre de mercado (amigable para el consumidor) de un dispositivo. Obtiene el nombre correcto para más de 10,000 dispositivos y se actualiza constantemente. Si desea utilizar mi biblioteca, haga clic en el siguiente enlace:

Biblioteca de AndroidDeviceNames en Github


Si no lo hace desea utilizar la biblioteca anterior, entonces esta es la mejor solución para obtener un nombre de dispositivo amigable para el consumidor:

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

Ejemplo de mi Verizon HTC One M8:

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

Resultado:

HTC6525LVW

HTC One (M8)

 236
Author: Jared Rummler,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-21 09:37:35

Utilizo el siguiente código para obtener el nombre completo del dispositivo. Obtiene cadenas de modelo y fabricante y las concatena a menos que la cadena de modelo ya contenga el nombre del fabricante (en algunos teléfonos lo hace):

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

 

Aquí hay algunos ejemplos de nombres de dispositivos que obtuve de los usuarios:

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

 391
Author: Idolon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-13 15:21:11
 111
Author: Mirko N.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-01-03 16:23:53

En realidad eso no es 100% correcto. Eso puede darle Modelo (a veces números).
Le dará el fabricante del teléfono (HTC parte de su solicitud):

 Build.MANUFACTURER

Para un nombre de producto:

 Build.PRODUCT
 31
Author: Falcon165o,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-06 18:50:20

Para quienes buscan la lista completa de propiedades de Build aquí hay un ejemplo para 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

Puede listar fácilmente esas propiedades para su dispositivo en modo de depuración usando el diálogo" evaluar expresión " usando kotlin:

android.os.Build::class.java.fields.map { "Build.${it.name} = ${it.get(it.name)}"}.joinToString("\n")
 14
Author: ruX,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-16 12:28:56

Aparentemente necesitas usar la lista de Google en https://support.google.com/googleplay/answer/1727131

Las API no devuelven nada de lo que espero ni nada en la configuración. Para mi Motorola X esto es lo que consigo

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

Ir a la página mencionada anteriormente mapas "fantasma" a Moto X. Parece que esto podría ser un poco más simple...

 8
Author: Edwin Evans,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-12 17:36:02

Puede usar el siguiente código para obtener el nombre de la marca y modelo de marca del dispositivo.

 String brand = Build.BRAND; // for getting BrandName
 String model = Build.MODEL; // for getting Model of the device
 7
Author: RamakanthReddy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-09 05:29:16

Las siguientes cadenas son todas de uso cuando se desea recuperar fabricante, nombre del dispositivo, y / o el modelo:

String manufacturer = Build.MANUFACTURER;
String brand        = Build.BRAND;
String product      = Build.PRODUCT;
String model        = Build.MODEL;
 7
Author: silkfire,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-21 11:02:49
String deviceName = android.os.Build.MODEL; // returns model name 

String deviceManufacturer = android.os.Build.MANUFACTURER; // returns manufacturer
 6
Author: Ajay Pandya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-23 09:25:24

Aquí está mi código,Para obtener el Fabricante,la marca, la versión del sistema operativo y el nivel de API de soporte

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

Salida:

System.out: button press on device name = Lava Alfa L iris(5.0) API-21
 3
Author: Saurabh Gaddelpalliwar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-22 11:43:11

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)
    }
}
 2
Author: Francisco Pereira,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-28 13:36:24

Cambió un poco el código Idolons. Esto pondrá en mayúscula las palabras al obtener el modelo de dispositivo.

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();
    }
}
 0
Author: Xjasz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-10 06:01:58

Puede obtener el nombre del dispositivo del teléfono desde

BluetoothAdapter

En caso de que el teléfono no sea compatible con Bluetooth, debe construir el nombre del dispositivo desde

Android.operativo.Construir clase

Aquí está el código de ejemplo para obtener el nombre del dispositivo del teléfono.

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;
}
 0
Author: Sridhar Nalam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-19 04:08:21

Puede intentar la siguiente función y devolver su nombre de phoneModel en formato de cadena.

public String phoneModel() {

    return Build.MODEL;
}
 -2
Author: Quantum4U,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-18 08:18:46