Get Android Phone Model programmatically , How to get Device name and model programmatically in android?
Solution 1
On many popular devices the market name of the device is not available. For example, on the Samsung Galaxy S6 the value of Build.MODEL
could be "SM-G920F"
, "SM-G920I"
, or "SM-G920W8"
.
I created a small library that gets the market (consumer friendly) name of a device. It gets the correct name for over 10,000 devices and is constantly updated. If you wish to use my library click the link below:
AndroidDeviceNames Library on Github
If you do not want to use the library above, then this is the best solution for getting a consumer friendly device name:
/** 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();
}
Example from my Verizon HTC One M8:
// using method from above
System.out.println(getDeviceName());
// Using https://github.com/jaredrummler/AndroidDeviceNames
System.out.println(DeviceName.getDeviceName());
Result:
HTC6525LVW
HTC One (M8)
Solution 2
I use the following code to get the full device name. It gets model and manufacturer strings and concatenates them unless model string already contains manufacturer name (on some phones it does):
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);
}
}
Here are a few examples of device names I got from the users:
Samsung GT-S5830L
Motorola MB860
Sony Ericsson LT18i
LGE LG-P500
HTC Desire V
HTC Wildfire S A510e
…
Solution 3
Yes: Build.MODEL.
Solution 4
For whom who looking for full list of properties of Build
here is an example for 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
You can easily list those properties for your device in debug mode using "evaluate expression" dialog using kotlin:
android.os.Build::class.java.fields.map { "Build.${it.name} = ${it.get(it.name)}"}.joinToString("\n")
Solution 5
Actually that is not 100% correct. That can give you Model (sometime numbers).
Will get you the Manufacturer of the phone (HTC portion of your request):
Build.MANUFACTURER
For a product name:
Build.PRODUCT
Andrea Baccega
Updated on July 18, 2022Comments
-
Andrea Baccega almost 2 years
I would like to know if there is a way for reading the Phone Model programmatically in Android.
I would like to get a string like HTC Dream, Milestone, Sapphire or whatever...
-
Mike Ortiz almost 12 yearsI've found that
String name = Build.MANUFACTURER + " - " + Build.MODEL
to be the most useful combination. Build.PRODUCT sometimes uses an unexpected name. For example, on the Galaxy Nexus, it returns "takgu". Build.MODEL, on the other hand, is the user-facing value displayed under Settings->About Phone->Model number. -
Falcon165o almost 12 yearsA lot of it depends on the manufacturer; HTC devices (Evo 4G, 4G LTE, 3D and Slide) use what I stated above.
-
evilfish almost 10 yearsIt there a list somewhere that hold all possible answer you can get out of the phone. Say if you need to redirect a user on how to install something on a specific phone type or sell something to a specific model.
-
Idolon almost 10 years@evilfish Try this list from Google: support.google.com/googleplay/answer/1727131
-
Mohib Sheth over 9 yearsThanks Jared. I needed this today but for Xamarin.Android so translated your file to C#. If somebody else needs it, you can find it here. gist.github.com/mohibsheth/5e1b361ae49c257b8caf
-
Radon8472 over 9 yearsIs there a way to get the "human readable" devicename like "Xperia Z3" or "Galaxy S3" without this Devices class ? I don`t like to use a static list of all devices to be sure even all future devices will be supported.
-
Jared Rummler over 9 years@Radon8472 Have you tried the static factory method above named
getDeviceName()
? If that doesn't give you the results you are looking for there isn't a better solution that I know of. -
Radon8472 over 9 years@Jared: I already have a devicename like the results of 'getDeviceName()' but I like to display the name wich endusers know from their handy stores :(
-
Wahib Ul Haq over 9 yearsWorks perfectly on watch because I needed it for Android Wear.
-
Devrath about 9 yearsThank you so much for this Code :)
-
Raja Yogan almost 9 yearsHi all I wrote an angular module for this called ng-fone using the list from Jared. The below link gives instructions on how to use it. tphangout.com/?p=83
-
vaso123 almost 8 years@RajaYogan Waow, awesome. I want to detect the manufacturer by the model number, your array of objects is really cool for this. By the way, where did you get this big database?
-
Raja Yogan almost 8 years@karacsi_maci, I got the list from Jared Rummler's Library. Thank you.
-
Serge almost 7 yearsAXON 7 mini is in list. Yet where is regularly sized AXON?
-
Serge almost 7 yearsAXON 7 mini is in the list. Yet where is the regularly sized AXON?
-
Lynn Crumbling over 6 yearsThis answer does not improve on any of the other answers that said the same thing, and were left here a year ago.
-
user2923322 over 5 yearsTHANK YOU!! Note that permission BLUETOOTH is required for this to work.
-
Swathi over 5 yearsIt always gives me "Android SDK built for x86" when I try it with emulator. Cannot able to get the model name specifically in emulator run with different model name.
-
Clement Osei Tano over 5 yearsYes, that's the model of the emulator. Note that it even uses a similar name for the internal storage.
-
Sean over 4 yearsI've posted a shorter version with Kotlin's
capitalize
stackoverflow.com/a/59158474/1446466 -
ShriKant A about 3 yearsIn the above Github project used the public URL="storage.googleapis.com/play_public...." is it have trusted server certificate ..else these days (April 2021) Google will not allow app be distributed on Play Store if they detect insecure hostname verifier..@Jared Rummer
-
Tyler almost 3 yearsI don't understand why Google doesn't include something like Build.MARKET_NAME
-
Krrishnaaaa over 2 years
capitalize
is now deprecated. instead use this.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }