可以在flutter上获得唯一的ANDROID_ID吗? [英] Get unique ANDROID_ID on flutter is it possible?

查看:319
本文介绍了可以在flutter上获得唯一的ANDROID_ID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Flutter上获取Android上的唯一设备ID. 我已经尝试过该插件 device_info ,但是它不会返回我在Java中获得的ANDROID_ID Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

I would like to get the unique device id on android with Flutter. I've tried this plugin device_info but it doesn't return the ANDROID_ID that I get in java Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

我如何获得相同的ID?

how can I get the same id?

推荐答案

您可以按照自己的方式做,但并不可靠或不能保证.请继续阅读: https://developer.android.com/training/articles/user-data- ID

You can do what you did, but it is not reliable or guaranteed. Please read up on: https://developer.android.com/training/articles/user-data-ids

用于最佳处理唯一ID. 当然,您可以获得电话网络ID,但是如果该设备没有运营商,该怎么办. 您可以获取设备ID,但是如果该制造商返回null,该怎么办. 您可以获取广告商ID,通常建议这样做,但是它可以更改,不太可能更改,但是如果他们进行了出厂重置或类似的设置,则可以.

for best handling of unique IDs. Of course you can get the phone network ID, but what if that device doesn't have a carrier. You could get the device ID, but what if it returns null for that manufacturer. You could get the Advertiser ID, and this is often recommended, but it CAN CHANGE, it is unlikely to change, but if they do a factory reset or anything like that, it would.

因此,最好的选择是生成自己的唯一ID,并将其与应用程序一起在数据库实现或SharedPreferences中本地存储.

So your best bet might be to generate your own unique IDs and store them locally with the application either in a DB implementation or SharedPreferences.

所以要回答您的问题,如果您现有的听众使用了错误的,错误的使用唯一ID的做法,那么您应该使用ID/ELSE逻辑来创建ID工厂.

So to answer your question, if you have existing audience that you used the wrong, bad practice way of using unique IDs, then you should make an ID factory with if/else logic to fix it.

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中再次对其进行修复.

You could also just as easily do a one time check in your Application onCreate to fix anyone with wrong ID and then set a flag that you fixed it so you don't fix it again in sharedpref.

这篇关于可以在flutter上获得唯一的ANDROID_ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆