[Android] tapping push notification does nothing when app not running or in background
See original GitHub issueDescription of the problem:
Affected platform
- Android
- iOS
- electron
- web
OS of the development machine
- Windows
- macOS
- linux
Other information: This is the same as issue #1192, which was closed under the impression it was fixed with the latest beta (22). It still reproduces for me, but I have investigated it and am putting in a PR very soon.
Capacitor version: beta.22
node version: 10.13
npm version: 6.4
CocoaPods version: n/a
Steps to reproduce:
Send Firebase (FCM) message to Capacitor app not running in foreground. Tap on notification in Android’s notification panel.
Either nothing happens (app is not started or background app not brought to foreground), or the app is started up without sending the notification data to any of its listeners pushNotificationReceived
or pushNotificationActionPerformed
.
Link to sample project: n/a
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:13 (11 by maintainers)
Top GitHub Comments
We are moving to Capacitor and needed to support old and new systems, so notifications contained
click_action: ST_ACTIVATE
field. The solution was to add following intent-filter to main activity in AndroidManifest.xml:Thanks for the quick reply.
I am testing on Android 5.0 (minimum required by Capacitor).
I tried all payload combinations. Without “notification”, then without “data”, with both “notification” and “data”, with “click_event” and without, etc.
Just an example of what I am sending (via Node.js backend POST request to Firebase cloud) which works with the changes I proposed in the PR:
Without “notification” the notification doesn’t even arrive at all if the app is not running (background or killed).
Just looking at the code itself, I can’t figure out how Android ends up calling handleOnNewIntent in PushNotifications.java as there is nothing in the AndroidManifests, apart from
CapacitorFirebaseMessagingService
, that might deal with incoming Firebase messages when the app is not running in the foreground.In my case, when the Capacitor app is in the background or not running, the Firebase message results in a notification in Android’s notification panel, and tapping that notification does not make CapacitorFirebaseMessagingService’s
onMessageReceived
handle it.Could be old Android behaviour that doesn’t repro in later OS versions, but regardless, how would the code inside handleOnNewIntent (pushnotifications.java) get called, and how does any listener to
pushNotificationActionPerformed
get anything? Do later versions of Android somehow know to hook into the PushNotifications plugin and send an Intent there?Sorry if I overlooked something obvious.