PendingIntent send() not working on Android 12 when application is closed

1.9k views Asked by At

I'm trying to show an Activity in onMessageReceived of my FirebaseMessagingService. I've already asked user for permission and checked that it granted.

For Android <=11 simple start activity method worked correctly. Also, it works correctly for Android 12 for emulator.

    context.startActivity(Intent(context, MyActivity::class.java).apply {
       // add extra
        addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    })

But for real devices (Samsung and Xiaomi) with Android 12 such approach is not working. Also, I've tried PendingIntent without result:

val pendingIntent = PendingIntent.getActivity(
    context,
    0,
    Intent(context, MyActivity::class.java)
        .apply { // add extra },
    PendingIntent.FLAG_IMMUTABLE
)
pendingIntent.send()

Both approaches works, if the application is running. Any suggestions?

1

There are 1 answers

0
Thomas Meinhart On

If your application is in the background the notification is delivered to the device's system tray and is not handled by onMessageReceived.

Notifications handled by the system tray should just open your app.

More information can be found here