¿Cómo puedo obtener el nombre del dispositivo en Android?
¿Cómo puedo obtener el nombre del dispositivo mediante programación en Android?
Para mostrar el nombre / modelo del dispositivo en android use:
TextView tv1 = (TextView) findViewById(R.id.tv1); String str = android.os.Build.MODEL; tv1.setText(str);
Enlace a Android Build Class
Android.os.Build.MANUFACTURER + android.os.Build.MODEL
Con el fin de obtener el nombre de dispositivo de Android que tiene que agregar sólo una sola línea de código:
android.os.Build.MODEL;
Copie y pegue el código siguiente en sus proyectos onCreate()
:
super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv1 = (TextView) findViewById(R.id.tv1); String str = android.os.Build.MODEL; tv1.setText(str);
Para obtener el nombre del teléfono, por ejemplo: Galaxy s5 o similar, sólo tiene que añadir esto a sus dependencias:
compile 'com.jaredrummler:android-device-names:1.0.9'
Luego sincronizar proyecto, cuando termine, vaya a su clase java y utilice este código:
String mDeviceName = DeviceName.getDeviceName();
Y eso es.
Como otros mencionados, puede utilizar Build.MODEL
, Build.DEVICE
y puede obtener mucho más información sobre el dispositivo. Vaya a developer.android.com para leer más acerca de la clase Build
. BTW recuerde importar / agregar la import android.os.Build;
.
Un ejemplo sencillo:
StringBuffer infoBuffer = new StringBuffer(); infoBuffer.append("-------------------------------------\n"); infoBuffer.append("Model :" + Build.MODEL + "\n");//The end-user-visible name for the end product. infoBuffer.append("Device: " + Build.DEVICE + "\n");//The name of the industrial design. infoBuffer.append("Manufacturer: " + Build.MANUFACTURER + "\n");//The manufacturer of the product/hardware. infoBuffer.append("Board: " + Build.BOARD + "\n");//The name of the underlying board, like "goldfish". infoBuffer.append("Brand: " + Build.BRAND + "\n");//The consumer-visible brand with which the product/hardware will be associated, if any. infoBuffer.append("Serial: " + Build.SERIAL + "\n"); infoBuffer.append("-------------------------------------\n"); /* Android doc: This 'Serial' field was deprecated in API level O. Use getSerial() instead. A hardware serial number, if available. Alphanumeric only, case-insensitive. For apps targeting SDK higher than N_MR1 this field is set to UNKNOWN. */ //I just used AlertDialog to show device information AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this); dialog.setCancelable(true); dialog.setTitle("Device information:"); dialog.setMessage(infoBuffer);//StringBuffer which we appended the device informations. dialog.show();