Fix Android plugin: Handle intent and provide result if the intent is consumed #1121
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
When the Android OS opens the application with deeplink/applink (to simplify -
applink
), they are provided to the app inside theIntent
.The app can already be running and the
Activity
is in the foreground, registered to handle the Intent with a specific intent filter. Theapplink
will be delivered by the methodonNewIntent
.Flutter provides a way to handle such links - the
flutterPlugin
orflutterEngine
should implement the interfaceonNewIntentListener
.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 functiononNewIntent
.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
minor
branch OR my change is breaking and lands inmajor
branch.pubspec.yaml
according to the pub versioning philosophy.* DESCRIPTION OF YOUR CHANGE (@your-git-username)
).///
).dart analyze
.dart format
.flutter test
and all tests are passing.