Created
January 13, 2017 09:11
-
-
Save thanhit93/d1edabd2a8b8022d761da57a1417f73f to your computer and use it in GitHub Desktop.
This file contains 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 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