How can I get the device name in Android?

As others mentioned, you can use Build.MODEL, Build.DEVICE and you can get lot more info about device. Go to developer.android.com to read more about Build class. BTW remember to import/add import android.os.Build;.

A simple example:

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

You can get the device name from android.provider.Settings using :

Settings.Global.getString(context.getContentResolver(), "device_name")

To display the device name/model in android use:

TextView tv1 = (TextView) findViewById(R.id.tv1);
String str = android.os.Build.MODEL;
tv1.setText(str);

Link to Android Build Class


android.os.Build.MANUFACTURER + android.os.Build.MODEL

Tags:

Android