Skip to content

Instantly share code, notes, and snippets.

@thanhit93
Created January 13, 2017 09:11
Show Gist options
  • Save thanhit93/d1edabd2a8b8022d761da57a1417f73f to your computer and use it in GitHub Desktop.
Save thanhit93/d1edabd2a8b8022d761da57a1417f73f to your computer and use it in GitHub Desktop.
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 getAndroidVersion() {
return android.os.Build.VERSION.RELEASE;
}
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);
}
}
private String getDeviceId() {
String deviceId = "";
final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null) {
deviceId = mTelephony.getDeviceId();
} else {
deviceId = Secure.getString(getApplicationContext()
.getContentResolver(), Secure.ANDROID_ID);
}
return deviceId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment