I have found two ways to get device id in android but I do not which one of them better and what are the differences between them
Method 1
public static String getDeviceId2(Context context) {
String androidId = Settings.Secure.getString(
context.getContentResolver(), Settings.Secure.ANDROID_ID);
return androidId;
}
Method 2
public static String getDeviceId(Context context) {
if (PermissionManager.getInstance().hasSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == true) {
return ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
} else {
return "";
}
}