Use Instance ID as unique ID for my Android app

MobileAppDeveloper picture MobileAppDeveloper · Jun 26, 2017 · Viewed 7.4k times · Source

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.

Answer

AL. picture AL. · Jun 26, 2017

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.