How can I get the device name programmatically in Android?
-
2check out this link http://developer.android.com/reference/android/os/Build.html – Aravindhan Jul 05 '11 at 08:46
-
4possible duplicate of [Get Android Phone Model Programmatically](http://stackoverflow.com/questions/1995439/get-android-phone-model-programmatically) – kabuko Jun 13 '12 at 17:21
9 Answers
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);

- 8,268
- 10
- 49
- 84

- 3,637
- 2
- 20
- 18
-
Is there any work around to get the name not model like Samsung galaxy S. because no one is aware about model numbers only people knows handset with their names – Piyush Agarwal Jun 07 '13 at 11:45
-
-
3
android.os.Build.MANUFACTURER + android.os.Build.MODEL

- 6,040
- 7
- 52
- 85

- 2,135
- 21
- 21
-
3In Google Nexus devices that were made by LG - this will give you the wrong string - "LGE Nexus 5". You should use android.os.Build.BRAND + android.os.Build.MODEL. – FunkSoulBrother Nov 11 '15 at 09:02
You can get the device name from android.provider.Settings using :
Settings.Global.getString(context.getContentResolver(), "device_name")

- 42,756
- 16
- 135
- 159
-
1This should be the accepted answer as it provides the actual device name that the user can modify. The other answers give the device manufacturer name and device model. – ljtomev Apr 13 '21 at 07:56
-
-
Settings.Global.getString(requireContext().contentResolver, Settings.Global.DEVICE_NAME), Android Studio tells min API level is 25 – Amos Aug 22 '23 at 04:53
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();

- 21,001
- 12
- 102
- 104
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.

- 1
- 1

- 2,962
- 2
- 11
- 7
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);
-
this code is for getting Device name how do i get device profile name?? – Amitsharma May 06 '15 at 09:55
The name and model of your Android Device can be found like this:
String manufacturerModel = android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL;

- 101
- 6
-
Build.Model often is a kind of cryptic Model name; eg Samsung SM-T395 is a TabActive 2. So the answer ist precise but not very user friendly if this is used to display to user. – FrankKrumnow Feb 23 '23 at 14:44
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”);

- 12,251
- 9
- 52
- 88
Here is how to get the name that the user set in the "About Phone" "Device name" screen using adb:
$ adb shell 'settings get global device_name'

- 1
- 2