我看到了一个我最好的问题Is there a unique Android device ID?
我使用了一些以下代码来获取唯一ID。
public static String getDeviceId(Activity context) {
PermissionsChecker checker = new PermissionsChecker(context);
if (checker.lacksPermissions(Manifest.permission.READ_PHONE_STATE))
PermissionsActivity.startActivityForResult(context, 0, REQUIRED_PERMISSION);
else {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice = tm.getDeviceId();
final String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32));
return deviceUuid.toString();
}
return null;
}
但是我在悬停时会收到一些警告
tm.getDeviceId();
和
Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
如下:
建议不要使用getString来获取设备标识符。
除高价值防欺诈和高级电话用例外,不建议使用设备标识符。对于广告用例,请使用AdvertisingIdClient $ Info#getId并使用InstanceId#getId进行分析。
有什么解决方案吗?它有害还是其他什么?
你无法真正“解决”这个警告。
但是如果你想要,可以通过添加@SuppressLint(“HardwareIds”)来禁用警告,这将解决这个问题。
请注意,通过此警告,Lint有机会重新考虑您是否需要发布。