Handling remote notifications? (Android)

I send notifications from my server to a player when it’s his turn to act on a table. The problem is that the user can have several tables and he receives a lot of notifications.

What I want to do:

* If there is already a notification it should be updated (or canceled)

* If the app is active it should be dismissed

I have tried to use a collapse_key to group them but I *think* they only group them if the app is inactive, if it’s active they are received one by one (which is as expected I would guess but not really what I want)

Any help with this is highly appreciated!

Best regards,

Tomas

Anyone that can guide me to an answer with this?

Best regards,

Tomas

So basically if I call system.cancelNotification() it seems to work pretty descent but it still plays the sound. It is being cut-off though but it still plays it.

local function listener( event ) if ( event.type == "remote" ) then print("Remote Note") if \_G.IsAppRunning == true then print("App is running, cancel note") system.cancelNotification() end elseif ( event.type == "local" ) then elseif ( event.type == "remoteRegistration" ) then system.cancelNotification() -- Move to start? else end end function M.start() Runtime:addEventListener( "notification", listener ) end

Best regards,

Tomas

Have no one else had this problem before?

Best regards,

Tomas

I’m sending from my server when its users turn as well, and have multiple tables too actually.

When I send a notification to a user I keep a record of that notification being sent on the server. If another notification comes of the same type and I still have a record of previous notification I ignore that notification.

Whenever a user comes online I clear all record of notifications being sent to that user and the process is reset.

Can you tell me how you ignore the notifications?

As you can see above I cancel the notifications now if the app is running but a little bit of the sound is still being played.

This is a turn based game so the server doesn’t know if the player is online or not, only when he last connected (sent a message) to the server.

Best regards,

Tomas

All the notification sending happens on the server in my case. This may not work for you because I keep a live connection from user to server while app is open.

Happens something like this:

  • User A makes turn and sends to server the game data and to send User B a notification.
  • Server sends notification to B and now has a record of that happening.
  • User A makes another turn and sends to server to send user B a notification again.
  • Server sees it already sent a notification to B for this particular game and server ignores that notification request and does not send another notification to A.
  • User B opens game and is logged in on server.  Server clears all notification for that user.
  • User A makes a turn and sends to server, but server sees User B is online and does not send notification (I guess you can’t do this part?)

One idea that might be a quick fix for you but kind of hacky I guess. Put a short silence in front of your notification sound so that when its cut off on cancel notification it hasn’t yet played anything.

Thanks a lot Jon, I just needed some perspective on things.

What I did is like this:

Every time the user opens the app the connects to the server and an “Online” flag is set.

When the user closes the app a message is sent and an “Offline” flag is set.

This makes it possible for me to only send one message when the user is offline and no message when the user is offline.

It might be some problems when the user enters a zone without Internet and the app closes but that’s acceptable for me. Otherwise there are workarounds for that as well. Thanks a lot Jon.

Best regards,

Tomas

Anyone that can guide me to an answer with this?

Best regards,

Tomas

So basically if I call system.cancelNotification() it seems to work pretty descent but it still plays the sound. It is being cut-off though but it still plays it.

local function listener( event ) if ( event.type == "remote" ) then print("Remote Note") if \_G.IsAppRunning == true then print("App is running, cancel note") system.cancelNotification() end elseif ( event.type == "local" ) then elseif ( event.type == "remoteRegistration" ) then system.cancelNotification() -- Move to start? else end end function M.start() Runtime:addEventListener( "notification", listener ) end

Best regards,

Tomas

Have no one else had this problem before?

Best regards,

Tomas

I’m sending from my server when its users turn as well, and have multiple tables too actually.

When I send a notification to a user I keep a record of that notification being sent on the server. If another notification comes of the same type and I still have a record of previous notification I ignore that notification.

Whenever a user comes online I clear all record of notifications being sent to that user and the process is reset.

Can you tell me how you ignore the notifications?

As you can see above I cancel the notifications now if the app is running but a little bit of the sound is still being played.

This is a turn based game so the server doesn’t know if the player is online or not, only when he last connected (sent a message) to the server.

Best regards,

Tomas

All the notification sending happens on the server in my case. This may not work for you because I keep a live connection from user to server while app is open.

Happens something like this:

  • User A makes turn and sends to server the game data and to send User B a notification.
  • Server sends notification to B and now has a record of that happening.
  • User A makes another turn and sends to server to send user B a notification again.
  • Server sees it already sent a notification to B for this particular game and server ignores that notification request and does not send another notification to A.
  • User B opens game and is logged in on server.  Server clears all notification for that user.
  • User A makes a turn and sends to server, but server sees User B is online and does not send notification (I guess you can’t do this part?)

One idea that might be a quick fix for you but kind of hacky I guess. Put a short silence in front of your notification sound so that when its cut off on cancel notification it hasn’t yet played anything.

Thanks a lot Jon, I just needed some perspective on things.

What I did is like this:

Every time the user opens the app the connects to the server and an “Online” flag is set.

When the user closes the app a message is sent and an “Offline” flag is set.

This makes it possible for me to only send one message when the user is offline and no message when the user is offline.

It might be some problems when the user enters a zone without Internet and the app closes but that’s acceptable for me. Otherwise there are workarounds for that as well. Thanks a lot Jon.

Best regards,

Tomas