Skip to content

Fix Android plugin: Handle intent and provide result if the intent is consumed #1121

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

Open
wants to merge 2 commits into
base: minor
Choose a base branch
from

Conversation

relaxedSoul
Copy link

Context

When the Android OS opens the application with deeplink/applink (to simplify - applink), they are provided to the app inside the Intent.
The app can already be running and the Activity is in the foreground, registered to handle the Intent with a specific intent filter. The applink will be delivered by the method onNewIntent.
Flutter provides a way to handle such links - the flutterPlugin or flutterEngine should implement the interface onNewIntentListener.

The bug

The audio service implements this interface, but if the applink is supposed to be delivered to another plugin, its listener will not be called, because the audio service listener always returns true from the function onNewIntent.
If another listener waits for intent, it will never receive it, even if the applink was not for audio service, but for another purpose.

Where it happens

AudioServicePlugin.java -> onAttachedToActivity method.
The method registerOnNewIntentListener() is called, and from now on, the intents will be handled by newIntentListener.
The implementation of the interface, its single method, always returns true.
The value returned here is used by Flutter (OS, eventually) to call or not call the next listener in the... I don't know if a list or a stack. I believe in the list (FIFO).
The result true signs that the intent was consumed, and no other listeners should be called.

Fix

As far as I see, there is a method inside that makes the check, and if it fails, the intent is not handled at all. I believe this check also should deliver the result "is handled" back to the caller, and the result should be returned.

Issues or tickets, or PRs in repo

I couldn't find anything related to this bug, but there is a chance the changes will solve some other bugs: the onNewIntent handling can have a large impact on various plugins, which depend on app link handling or deeplinks.

Pre-launch Checklist

  • I read the CONTRIBUTING.md and followed the process outlined there for submitting PRs.
  • My change is not breaking and lands in minor branch OR my change is breaking and lands in major branch.
  • If I'm the first to contribute to the next version, I incremented the version number in pubspec.yaml according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change (format: * DESCRIPTION OF YOUR CHANGE (@your-git-username)).
  • I updated/added relevant documentation (doc comments with ///).
  • I ran dart analyze.
  • I ran dart format.
  • I ran flutter test and all tests are passing.

@relaxedSoul relaxedSoul changed the title Bug fix. Android plugin: Handle intent and provide result if the intent is consumed Fix Android plugin: Handle intent and provide result if the intent is consumed May 20, 2025
When a new intent arrives, there can be several listeners for them. In case if the intent was handled by AudioService it should be consumed, and other listeners should not receive it. Otherwise, we need to return `false` in listener's method result. In this case the intent will go to the next listener.
@relaxedSoul relaxedSoul force-pushed the pass-app-links-if-not-consumed branch from 4f5c14b to 4c6ece9 Compare May 21, 2025 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant