【问题标题】:Get unique ANDROID_ID on flutter is it possible?在颤动上获得唯一的 ANDROID_ID 是可能的吗?
【发布时间】:2018-10-20 00:22:52
【问题描述】:

我想使用 Flutter 在 android 上获取唯一的设备 ID。 我试过这个插件device_info,但它没有返回我在java中得到的ANDROID_ID Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

我怎样才能得到相同的id?

【问题讨论】:

    标签: android flutter android-identifiers flutter-dependencies


    【解决方案1】:

    在这种情况下,使用平台特定代码和 Flutter 平台通道设置可能会更简单

    然后,您可以使用问题中包含的 Java 代码,并在需要时通过平台通道将 Android ID 传递给您的 Flutter 应用程序。

    Writing custom platform-specific code with platform channels

    【讨论】:

    • 谢谢,它工作正常!我有问题,因为我没有设置 JDK。
    【解决方案2】:

    你可以做你做过的事,但这并不可靠或保证。请继续阅读: https://developer.android.com/training/articles/user-data-ids

    为了更好地处理唯一 ID。 当然,您可以获得电话网络 ID,但如果该设备没有运营商怎么办。 您可以获得设备 ID,但如果它为该制造商返回 null 怎么办。 您可以获得广告商 ID,这通常是推荐的,但它可以更改,不太可能更改,但如果他们进行出厂重置或类似的事情,它会。

    因此,最好的办法可能是生成自己的唯一 ID,并将它们与应用程序一起存储在本地数据库实现或 SharedPreferences 中。

    因此,为了回答您的问题,如果您的现有受众使用了错误的、错误的使用唯一 ID 的做法,那么您应该使用 if/else 逻辑创建一个 ID 工厂来修复它。

    If (first time accessing an ID for this installed application)
       //createOne and store it
    else if(ID already exists and matches ANDROID_SECURE_ID method)
       //get it the old way, 
       //create new one, and update your access to APIs or DB with new associated ID so that you never hit this code path again
    else
       //use correct ID implementation that you created
    

    您也可以轻松地在您的应用程序 onCreate 中进行一次检查,以修复任何 ID 错误的人,然后设置一个您已修复的标志,这样您就不会在 sharedpref 中再次修复它。

    【讨论】:

      猜你喜欢
      • 2017-12-15
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 1970-01-01
      • 2015-09-07
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      相关资源
      最近更新 更多