简体   繁体   中英

Is there a way to delete push notifications in FCM?

In my application, I am offering video and voice calls between users. I'm using Firebase Realtime database and FCM as well to do so.

Here is the data that my notification is delivering:

data: { 
    channel_id: channel_id,
    user_id: user_id
}

In my FirebaseMessagingService class, I retrieve the data and open the Video/Call activity like so:

if(remoteMessage.getData().size > 0) {
        Intent intent = new Intent(this, VideoCallActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra("channel_id", remoteMessage.getData().get("channel_id"));
        intent.putExtra("user_id", remoteMessage.getData().get("user_id"));
        getApplicationContext().startActivity(intent);

    }

Everything is working perfectly even when the application is in background. However, I'm facing this issue:

If an user didn't have internet connection when he was called, when he connects to internet his phone will automatically start the VideoCallActivity even if the call has been aborted (by the caller) and the notification removed from Firebase real time database.

So, please is there a way to cancel sent notifications, or know the delivery status of those notifications, or another way around to do so? That will allow me to add the list of missed calls for users.

Thanks!

In a scenario like this, I know of two options:

  1. Send another FCM message when the call is cancelled
  2. Only use FCM to send a tickle

Send another FCM message when the call is cancelled

One of the properties you can give an FCM message is an collapse_key . When you send a message with a collapse_key , that message replaces any previous message with the same collapse_key value.

You can use this to send a "nope, forget about it" message, when the user cancels the call.

Only use FCM to send a tickle

Alternatively you can have the FCM message just be a so-called tickle: an almost empty message, that just tells the app to wake up and go check its queue of incoming messages in the database.

That way: if the call is still in the database, the app can pick it up. But if there is no call in the database, it can just do nothing.

You'll want to do this type of database interaction in a service, so that it can run when the app is backgrounded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM