Firebase Cloud Messaging Group Fires

I am going to develop an application using the function of device groups. As I understand it, I need to first send the current registration token that I get on the Android client in the onTokenRefresh method to the server, and then add this registration token to the appropriate device group (or create it if it does not exist) via an HTTP request. I see, however, the possibility of leakage of registration tokens, since a user of an Android application can, for example, erase application data several times. How to prevent this? What happens when a limit of 20 members is exceeded? And is it possible to check if any group exists or not?

+5
source share
2 answers

I see, however, the possibility of leakage of registration tokens, since a user of an Android application can, for example, erase application data several times. How to prevent this?

If you did not allow you to disable Clear Data for your application in App Manager, you should refer to this message. The accepted answer states that this is not possible.

However, Jakar's answer provides a workaround, instead of Clear Data, instead of Manage Spaces, Manage Spaces will be displayed. I have not tried it yet, so I can’t say for sure. Despite this, upvotes speak for themselves.

But if ever the application data is erased / cleared by the user, you should refer to what is indicated in the FirebaseInstanceId documents:

The instance identifier is stable unless:

  • Application removes instance id

  • The application is restored on the new device

  • User uninstalls / reinstalls the application

  • User deletes application data

In the above cases, a new Instance ID , and the application needs to recreate the authorization tokens previously created onTokenRefresh() .


What happens if the 20-member limit is exceeded?

Not sure if the question is here. But if you relate to adding devices to a device group more than the maximum ...

Could not find this as indicated in FCM: Messaging with devices , but if you are linking to Add a section to the group :

A successful operation returns a notification_key .

So, I think that if you ever try to add another device to an already configured device group, the operation will fail .

I suggest instead of the topic , if you think you are over 20. But I do not know what you use -case is, therefore .. your call.


And is it possible to check if any group exists or not?

To do this, you must use notification_key and notification_key_name . According to docs :

notification_key_name is a name or identifier (for example, this is a username) that is unique to this group. notification_key_name and notification_key are unique to a group of registration tokens. It is important that notification_key_name unique to the client application if you have multiple client applications for the same sender ID. This ensures that messages are sent only to the target application.

And emphasizing the statement:

The basic management of device groups β€” creating and deleting groups, as well as adding or removing devices β€” is usually done through the application server.

The keys and names must be on your server so you can check if it exists or not.

+3
source

I am currently doing the following with some success, but not fully tested or scaled.

The application uses firebase as the backend, and I add FCM to implement push notifications.

I need groups to handle when a user can be on different devices or on multiple devices.

I save the return value of notification_key and register_id (token) for each device with ie profile

 profiles -profile_id -FCM -notification_key:value -registration_ids -device_1_uuid:token_for_device_1 -device_2_uuid:token_for_device_2 

When a user first subscribes, there is no data in the FCM node, i.e. no notification_key and no registration_ids

Each time a user subscribes, they connect to their profile_id.

I get the FCM token and then

If there is no notification button (that is, for the first time on any device), I create a group using profile_id as name_iz_i_i_i_i_name and save the return notification_key button.

If there is a notification on the new device (the input or the first entrance to the new device), I see if there is a registration name for the current device, and if not (the first entrance to the new device), add device_uuid: a pair of tokens to the registration_id.

If there is (return sign-on), I delete the saved token from the FCM group and replace the old token in my saved registration identifiers with the just received token.

Now I can tell all the devices used by this user (profile) by sending them to my id_ profile, and I should not skip tokens, because I delete the old ones.

However, I do not know, because the API does not seem to just read the group and tokens, so the groups can be cleared from time to time.

Also, my early code was tapped and I didn’t capture message_key, so now I can’t add, delete or do anything in one of my groups. I hate the idea that I will have to leave the fierce groups lying in the cloud of the fire base forever.

I think FCM should provide more access to the API to help us keep the place clean.

+2
source

All Articles