Support Topics Documentation Slack YouTube Blog

Push notification from one device to another

Hello,
I probably asked similar question couple of years back but maybe with backendless 5 things have changed so I just want to get your opinion on this.
Like Facebook, I am implementing notifications when a post is liked.
My thought is that User A likes post from User B. User A knows User B Object ID (as the owner of the post).
User A will send a message to a channel that is named the same as user B’s object ID. User B will receive the message because he subscribed to a channel created by himself

  1. Given that there will many users (and as a result many channels), there is no issue right?
  2. Will this message be received while the app is closed/background. Or is receiver device ID always need to be known by the sender?
  3. Is this good solution?

Thank you

Hi SnakeEyes

Have you tried to use “pushSinglecast” api? You can send push notifications to specific devices.
All the device registrations are stored in DeviceRegistration Data Table with relation to user.

here is a doc: https://backendless.com/docs/android/push_target_specific_devices.html

Regards, Vlad

Hi Vladimir,
Thanks for your answer. Alright so the push single cast is what I need to use to receive a message regardless whether app is foreground or background right?
Yes device registration is 1:1 to user table. But I have the object Id of the user so I need to go the opposite way. Wouldn’t make more sense if the the user table has the 1:1 mapping instead? As usually query user tables to get user object along with its device id, not the other way around

… what I need to use to receive a message regardless whether app is foreground or background right?

yes, device should receive and display push notifications, but as far as I know displaying is depends on channel settings

Yes device registration is 1:1 to user table. But I have the object Id of the user so I need to go the opposite way. Wouldn’t make more sense if the the user table has the 1:1 mapping instead? As usually query user tables to get user object along with its device id, not the other way around

if there will be 1:1 relationship user won’t have an possibility to have more than one registered device, for ex: user might be logged in to the same account on smartphone and tablet as well at the same time, and as result in Data Table there will be two device registrations with link to the same user object.

you can retrieve a list of devices for specific user by its objectId,

user.objectId='USER_OBJECT_ID'

Perfect. Thanks A LOT Vladimir. This helps greatly.
Last question, is there a way I can intercept this notification message before it is displayed to the user? Basically, based on the app setting, I might need to mute it so I want to not show it if it should be muted.

Offcourse I am talking regardless if the app is background or forground

I figured it out. I had to override BackendlessFCMService class to control things. All is good now :slight_smile:

1 Like