-
Notifications
You must be signed in to change notification settings - Fork 6k
support uri intent launcher in android #21275
Conversation
if (getIntent().hasExtra(EXTRA_INITIAL_ROUTE)) { | ||
return getIntent().getStringExtra(EXTRA_INITIAL_ROUTE); | ||
Intent intent = getIntent(); | ||
Uri data = intent.getData(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The developer still need to manually modify the AndroidManifest to add an intent filter. I wonder if we can automatically generate the intent filter for them so it will be much simpler for flutter beginner to work with deeplink.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change the default create template's AndroidManifest if I understood
if (getIntent().hasExtra(EXTRA_INITIAL_ROUTE)) { | ||
return getIntent().getStringExtra(EXTRA_INITIAL_ROUTE); | ||
Intent intent = getIntent(); | ||
Uri data = intent.getData(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change the default create template's AndroidManifest if I understood
shell/platform/android/io/flutter/embedding/android/FlutterActivity.java
Show resolved
Hide resolved
@Test | ||
public void itCreatesNewEngineIntentWithLaunchUri() { | ||
Intent intent = FlutterActivity.createDefaultIntent(RuntimeEnvironment.application); | ||
intent.setData(Uri.parse("http://myApp/custom/route")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @chunhtai what is up with the myApp
portion of the URL? It seems to be ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, currently it only returns URI.path.
I will change to return full URI per our discussion.
With this change in place, what do I need to do (e.g. add to the manifest) to make it work? |
With this patch, developer only need to add intent-filter in manifest, and the Windows.defaultRouteName will have the url string from the deeplink. |
One thing i am still not certain is that whether we should add the api (maybe through plugin) to override this behavior. For example if user want to do a preprocess on the URL |
Can you post an example of what that looks like into the PR description so we have it all in one place? |
3909e53
to
5e0dffd
Compare
This is ready for another look! |
Is this support meant for full-Flutter apps only? i.e. what happens with custom engines? What happens on |
Ah yes, we should deal with on newIntent too |
We talked about this offline, but is this the correct behavior we want for an app that is already running? Is there a way to navigate back to the way the app was before launching the url? The physical back button? It seems like the back button would take you to what you are looking at before you launched the url, like the web browser. |
That would be up to the developer to decide. In the Router, when a new URL is given to you, you can decide whether you want to put a new page on top of what's already visible (and provide a back button in the app) or whether you want to send the user to a different location in the app "loosing" their old state. |
I am not quite sure about custom engines. Did you mean developer modify the engine code and compile? I don't think that is within the scope of this change. |
Sorry, that's not what I meant. I meant creating a FlutterActivity with a self-supplied engine instance which is the primary recommendation for add-to-app users. i.e. do you intend to make deep links on Android (where the users filtered the intent to the Flutter activity in their add-to-app AndroidManifest) work in add-to-app scenarios? |
@xster yes, I think we should support this use case too. I am not too familiar with this workflow, does it go through FlutterFragmentActivity? If I added the getinitialroute on the FlutterFragmentActivity it should work as expected? |
Isn't the way it is implemented right now always create a new Activity? There is no sending of a message to Flutter that allows the developer to decide how to handle it. |
No I just double check, it just bring the existing activity to the front. Sorry for the confusing earlier |
@@ -782,8 +783,13 @@ public String getDartEntrypointFunctionName() { | |||
*/ | |||
@NonNull | |||
public String getInitialRoute() { | |||
if (getIntent().hasExtra(EXTRA_INITIAL_ROUTE)) { | |||
return getIntent().getStringExtra(EXTRA_INITIAL_ROUTE); | |||
Intent intent = getIntent(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how did you decide on the order? of whether to take the data string of the intent vs reading from the extra flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I make uri launch takes priority with no specific reason. Is there a desired order here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if EXTRA_INITIAL_ROUTE is present, it means the users had very specifically instructed it. I would have it take precedence.
String data in an intent could theoretically be anything and the engine doesn't do any validation here. Does the framework react in the right way if one just sends adb shell am start --es "blah blah"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--es will send the string to extra so it will not affect the intent.getData();
the getData always returns an URI and it must pass the intent filter, so I think we should be fine.
flutterEngine.getActivityControlSurface().onNewIntent(intent); | ||
Uri data = intent.getData(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a little bit of inconsistently between here and the getinitialroute
Have stuff in flutteractivity/fragment if you expect subclass developers to actively decide whether they want to keep or override this behavior.
If the same behavior's in both activity and fragment, just move them to the delegate (and make sure to document what the default behavior is in the javadoc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest LG
Is there a blocker to landing this? |
No, I will get to this by the end of this week |
cfb085c
to
f7b7af9
Compare
Hi @xster I refactor the getinitialroute to delegate, can you take another look to see if it still looks good? |
@xster Can you take another look? Let's land this now that the tree is open. |
LGTM, thanks |
* 000bf4b Roll Skia from 2d2f82c00aeb to 5c7bb326a7b3 (33 revisions) (flutter/engine#22059) * ae92dbf Roll Fuchsia Linux SDK from lPMs_KwnU... to gqS_DIjN4... (flutter/engine#22057) * 92cd74e Roll Fuchsia Mac SDK from pZ9FgVZTK... to WLxBkBnZa... (flutter/engine#22055) * e51c710 Roll Dart SDK from a3d902d8598e to 9f907e198970 (2 revisions) (flutter/engine#22058) * 326b202 Reland fuchsia external view embedder will be shared with platform view (flutter/engine#22008) * a9a9a2f Roll Skia from 5c7bb326a7b3 to 65674e4c2e56 (3 revisions) (flutter/engine#22060) * 1233fe4 Revert "Revert "Explicitly make the X connection for EGL. (#21831)" (#21851)" (flutter/engine#21871) * aed8e01 Fixes Edge trigger route change announcement (flutter/engine#21975) * 6bc70e4 Reland: Migration to PlatformDispatcher and multi-window (flutter/engine#21932) * 5ca5e26 Add FlEventChannel (flutter/engine#21316) * 77b0052 Roll Skia from 65674e4c2e56 to 01b05e5b830b (3 revisions) (flutter/engine#22062) * 3d27fd5 Support loading assets from Android dynamic feature modules (flutter/engine#21504) * 742dfbe support uri intent launcher in android (flutter/engine#21275) * cde1e3f Auto detect mode to determine which rendering backend to use. (flutter/engine#21852) * 329ccf7 Roll Skia from 01b05e5b830b to 53281c712159 (1 revision) (flutter/engine#22065) * cde78c1 Add a golden scenario test for fallback font rendering on iOS take 2 (flutter/engine#22033) * 4f4599b Roll Dart SDK from 9f907e198970 to 37ccceacad41 (3 revisions) (flutter/engine#22069) * f0b10c5 [web] Prevent using DOM nodes for canvas with large number of draws (flutter/engine#22064) * a86ba57 Roll Fuchsia Mac SDK from WLxBkBnZa... to zDfaxkqlv... (flutter/engine#22073) * 645198a Roll Fuchsia Linux SDK from gqS_DIjN4... to vuKxZmSVj... (flutter/engine#22074) * 0b26570 Revert dart rolls (flutter/engine#22078)
There should be a way to migrate to this capability since this is a breaking change. Some older apps already implement their own custom intent handling mechanism. |
This reverts commit 742dfbe.
…" (flutter#22298)" This reverts commit f61cbc0.
…" (flutter#22298)" This reverts commit f61cbc0.
* support uri intent launcher in android * fix comment
* Revert "Revert "support uri intent launcher in android (flutter#21275)" (flutter#22298)" This reverts commit f61cbc0. * reland support uri launch for android * refactor * update * fix test * addressing comments * addressing comments * revert throw error
Description
Adds support to uri launch intent that is recommended in https://developer.android.com/training/app-links/verify-site-associations
With this patch, in order to set up deep link, the developer will need to add the intent filter in their AndroidManifest.xml
path/to/flutter_app/android/app/src/main/AndroidManifest.xml
This will catch intents such as
http://www.example.com/relative/path
, and the string will be stored in window.defaultRouteName when app launchRelated Issues
Fixes flutter/flutter#66148
Tests
I added the following tests:
see files
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.Breaking Change
Did any tests fail when you ran them? Please read handling breaking changes.