How can I get the device name in Android?

Android

Android Problem Overview


How can I get the device name programmatically in Android?

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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

Solution 3 - Android

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

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

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

Solution 5 - Android

In order to get android device name you have to add only a single line of code:

android.os.Build.MODEL;

Copy and paste the following code in your projects onCreate():

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv1 = (TextView) findViewById(R.id.tv1);
String str = android.os.Build.MODEL;
tv1.setText(str);

Solution 6 - Android

To get the phone name, for instance: Galaxy S5 or the like, just add this to your dependencies:

compile 'com.jaredrummler:android-device-names:1.0.9'

Then sync your project, when it finishes, go to your Java class and use this code:

String mDeviceName = DeviceName.getDeviceName();

And that's it.

Solution 7 - Android

The name and model of your Android Device can be found like this:

String manufacturerModel = android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL;

Solution 8 - Android

Using following way can get the device name and also in case user modify the device name, it can also get the updated name:

Settings.Secure.getString(getContentResolver(), “bluetooth_name”); 

Because bluetooth_name is not a documented API, in case it returns null, you can use following code instead: (note that this API is only available since Android 7.1 and per my testing, it CANNOT get the device name immediately after user modified)

Settings.System.getString(getContentResolver(), “device_name”);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCanerView Question on Stackoverflow
Solution 1 - AndroidRahul SharmaView Answer on Stackoverflow
Solution 2 - AndroiddiptiaView Answer on Stackoverflow
Solution 3 - AndroidBertrand MartelView Answer on Stackoverflow
Solution 4 - AndroidBlasankaView Answer on Stackoverflow
Solution 5 - AndroidRupokView Answer on Stackoverflow
Solution 6 - AndroidArmando Esparza GarcíaView Answer on Stackoverflow
Solution 7 - Androidkaran_for_youView Answer on Stackoverflow
Solution 8 - AndroidshizhenView Answer on Stackoverflow