使用实例ID作为我的Android应用程序的唯一ID [英] Use Instance ID as unique ID for my Android app

查看:194
本文介绍了使用实例ID作为我的Android应用程序的唯一ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的应用创建一个唯一的ID.如以下链接

我想使用InstanceID作为唯一ID.

String uniqueID = InstanceID.getInstance(context).getId();

由于进行了一些配置设置,因此我的服务器希望唯一ID仅使用小写字母.作为实例,id同时提供大写和小写字符.我正在考虑将每个实例ID字符转换为其对应的ASCII值,并将其作为我的唯一ID发送.这是正确的方法吗?

此外,我正在阅读有关FirebaseInstaceId的信息

https://firebase.google.com /docs/reference/android/com/google/firebase/iid/FirebaseInstanceId

是否建议对实例ID使用FirebaseInstanceId?我没有在任何地方的文档中找到它.请提出建议.

谢谢.

解决方案

使用InstanceID作为 app 的唯一ID应该很好,但是,根据使用情况,您必须请注意,无论何时卸载应用程序,InstanceID都会更改,因为它代表每个应用程序实例(因此命名为 InstanceId ),并且每个设备都不同.

如何处理数据完全取决于您.只要您能够相应地使用它即可.

InstanceId和FirebaseInstanceId在幕后调用相同的服务,只有FirebaseInstanceId是使用FCM时要使用的对象.尚未尝试同时使用两者,但是调用getId应该为同一实例返回相同的值(除非库中有所不同).

也请参见帖子.

I want to create a unique ID for my app. As given in the following link

I want to use InstanceID as the unique id.

String uniqueID = InstanceID.getInstance(context).getId();

Because of some configuration setup, my server expects unique id to be in lower case only. As instance id gives both lower and upper case characters. I was thinking to convert each instance id character to its corresponding ASCII value, and send that as my unique id. Would it be the right approach?

Also, I was reading about FirebaseInstaceId

https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId

Is it recommended to use FirebaseInstanceId over Instance Id? I did not find it written in the documentation anywhere. Please suggest.

Thanks.

解决方案

Using the InstanceID as a unique id for your app should be fine, however, depending on your use-case, you have to take note that the InstanceID changes whenever the app is uninstalled, since it represents each app instance (hence the naming InstanceId) and it is different per device.

How you process the data depends entirely up to you. So long as you are able to use it accordingly.

InstanceId and FirebaseInstanceId are calling the same service behind the scenes, only that FirebaseInstanceId is the object to use when you're using FCM. Haven't tried using both at the same time, but calling getId should return the same value for the same instance (unless there is something in the library that is different).

Also see this possibly helpful post.

这篇关于使用实例ID作为我的Android应用程序的唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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