Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Monday, December 14, 2015

Get Android Phone Model Programmatically

Get Android Phone Model Programmatically


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...

Thanks :)

Answer by Mirko N. for Get Android Phone Model Programmatically


Yes: Build.MODEL.

Answer by Falcon165o for Get Android Phone Model Programmatically


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  

Answer by Idolon for Get Android Phone Model Programmatically


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.startsWith(manufacturer)) {          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
?

Answer by RamakanthReddy for Get Android Phone Model Programmatically


you can use the following code for getting the brand name and brand model of the device.

 String brand = Build.BRAND; // for getting BrandName   String model = Build.MODEL; // for getting Model of the device  

Answer by silkfire for Get Android Phone Model Programmatically


The following strings are all of use when you want to retrieve manufacturer, name of the device, and/or the model:

String manufacturer = Build.MANUFACTURER;  String brand        = Build.BRAND;  String product      = Build.PRODUCT;  String model        = Build.MODEL;  

Answer by Ajay for Get Android Phone Model Programmatically


String deviceName = android.os.Build.MODEL; // returns model name

String deviceManufacturer = android.os.Build.MANUFACTURER; // returns manufacturer

Answer by Edwin Evans for Get Android Phone Model Programmatically


Apparently you need to use the list from Google at https://support.google.com/googleplay/answer/1727131

The APIs don't return anything I expect or anything in Settings. For my Motorola X this is what I get

   Build.MODEL = "XT1053"     Build.BRAND = "motorola"     Build.PRODUCT = "ghost"  

Going to the page mentioned above "ghost" maps to Moto X. Seems like this could be a tad simpler...

Answer by Jared Rummler for Get Android Phone Model Programmatically


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;      String phrase = "";      for (char c : arr) {          if (capitalizeNext && Character.isLetter(c)) {              phrase += Character.toUpperCase(c);              capitalizeNext = false;              continue;          } else if (Character.isWhitespace(c)) {              capitalizeNext = true;          }          phrase += c;      }      return phrase;  }  

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)


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 71

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.