Skip to content

Instantly share code, notes, and snippets.

@umesh0492
Last active January 16, 2016 16:49
Show Gist options
  • Save umesh0492/07ebf296dd646f254f9e to your computer and use it in GitHub Desktop.
Save umesh0492/07ebf296dd646f254f9e to your computer and use it in GitHub Desktop.
Android - Get Device Info
1. Make Default Constractor
2. You have object with all the properties, you had provided in information class.
3. Want json convert it new
//Snippet
Information information = new Information();
String information_json = new Gson().toJson(information);
public class Information{
int appVersion = BuildConfig.VERSION_CODE;
String deviceModel = Utils.getDeviceName();
String osVersion = Build.VERSION.RELEASE;
//String gcmId = App.getPreferenceManager().getGcmRegId();
//String userEmail = App.getPreferenceManager().getEmail();
//double lat = App.getPreferenceManager().getCurrentLatitude();
//double lng = App.getPreferenceManager().getCurrentLongitude();
// can add anything
public int getAppVersion() {
return appVersion;
}
public String getDeviceModel() {
return deviceModel;
}
public String getOsVersion() {
return osVersion;
}
/*
public String getGcmId() {
return gcmId;
}
public double getLat() {
return lat;
}
public double getLng() {
return lng;
}
public String getUserEmail() {
return userEmail;
}
*/
}
public static String getDeviceName() {
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
if (model.startsWith(manufacturer)) {
return capitalize(model);
} else {
return capitalize(manufacturer) + " " + model;
}
}
private static 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment