Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification events are not checked for non-FCM/non-APNS related notifications #23

Open
Bungeefan opened this issue Jul 28, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Bungeefan
Copy link

Currently, onNotificationTap is called whenever an intent with data is delivered to the activity and notificationTapWhichLaunchedAppFromTerminated returns data for all notification intents that launched the app, even the local ones.
This, for example, interferes with the flutter_local_notifications package, as local notifications are now triggering two callbacks.
However, in turn, Flutter Local Notifications checks for its own notifications and doesn't trigger when FCM/APNS notifications are tapped.

I could replicate the same behavior on both Android and iOS.

Android

One solution would be to specifically check for FCM Intent Actions in the following places:
Here:

override fun onNewIntent(intent: Intent): Boolean {
if (mainActivity != null) {
mainActivity!!.intent = intent
}
handleRemoteMessageIntent(
intent
) { message ->
// Application already running when notification is tapped
pushHostHandlers?.onNotificationTap(message)
}
return false
}

and here:
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
Log.v(TAG, "ActivityAware#onAttachedToActivity called")
isMainActivityRunning = true
val mainActivity = binding.activity
this.mainActivity = mainActivity
binding.addOnNewIntentListener(this)
binding.addRequestPermissionsResultListener(this)
handleRemoteMessageIntent(
mainActivity.intent
) { message ->
// Notification caused an app to launched
// Only saving the map because title/body are not provided in the RemoteMessage
pushHostHandlers?.notificationTapPayloadWhichLaunchedApp = message.toPushRemoteMessage().data
}
}

However, as far as my research went, I found out that FCM either uses some hard-coded actions depending on the actual notification or ask the PackageManager for an intent, this was in our case ACTION_MAIN but could "theoretically" be any other valid action (lacking experience to answer this confidently).

Therefore, another, not so great, solution would be to just check for the keys used by popular Flutter Notification packages.

Used Intent Actions:

iOS:

Collaborators are welcome to edit their research in, as my iOS experience is very limited.

TBD.

Workaround

My current workaround just checks for the payload key in the data (however, this only works as long as you always have a payload for local notifications!):

// "payload" means it's a local notification, handle elsewhere.
if (data.containsKey("payload")) return;
@ben-xD ben-xD added the bug Something isn't working label Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants