fenchai
fenchai

Reputation: 598

How do I clear Notifications when I open the app manually and they are not tapped?

I managed to make a Firebase cloud function to send me notifications of the latest chat msg. Everything works well.

The notifications arrive when the app is in the background or never started but I can still receive it while the app is in the foreground just fine.

Working fine:

The Problem:

Idea:

Upvotes: 3

Views: 2241

Answers (1)

K.Amanov
K.Amanov

Reputation: 1618

Write something like in MainActivity.kt this if you use Kotlin:

package com.posignal.app

import android.app.NotificationManager
import android.content.Context
import io.flutter.embedding.android.FlutterActivity


class MainActivity: FlutterActivity() {

    override fun onResume() {
        super.onResume()
        closeAllNotifications();
    }

    private fun closeAllNotifications() {
        val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        notificationManager.cancelAll()
    }

}

Upvotes: 2

Related Questions