Last active
January 16, 2016 16:49
-
-
Save umesh0492/07ebf296dd646f254f9e to your computer and use it in GitHub Desktop.
Android - Get Device Info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
*/ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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