考虑到没有恢复出厂设置,我应该使用 ANDROID_ID 作为设备标识吗?



>我正在开发一个Android应用程序,其中单个用户只能使用相同的Gmail帐户(用于登录(在一台设备中使用该应用程序。如果用户想要在其他设备上登录应用,则无法使用同一 Gmail 帐户登录。我正在使用应用程序中的ANDROID_ID来使用以下命令来识别唯一设备--

Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);

在这种情况下,这是正确的选择吗,因为我在开发人员网站上看到

Avoid using hardware identifiers. In most use cases, you can avoid using hardware identifiers, such as 
SSAID (Android ID), without limiting required functionality.
Android 10 (API level 29) adds restrictions for non-resettable dentifiers, which include both 
IMEI and serial number. Your app must be a device or profile owner app, have
special carrier permissions, or have the READ_PRIVILEGED_PHONE_STATE privileged permission
in order to access these identifiers.

文档链接-

https://developer.android.com/training/articles/user-data-ids

或者有没有其他方法可以做到上述操作?提前谢谢。

如果可能,请在您的使用案例中使用 FirebaseInstanceId。Firebase 实例 ID 为每个应用实例提供唯一标识符,以及用于验证和授权操作的机制。

  1. 实例 ID 是稳定的,除非:

  2. 应用删除实例 ID

  3. 应用已在新设备上恢复

  4. 用户卸载/重新安装应用

  5. 用户清除应用数据

如果您不想使用 FirebaseInstanceId,可以查找自定义的全局唯一 ID (GUID( 来唯一标识应用实例。

String uniqueID = UUID.randomUUID().toString();

您可以使用此 GUID 来确定是否只有一个设备附加到 Gmail ID。

你可以定义自己的规则来生成一个 unqiue id,然后将其保存在 sp 上。 每次您应该检查,获取它并与服务提供的数据进行比较。

或者您也可以使用建议 ID 作为 unqiue 设备 ID。

最新更新