Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 23cf9be

Browse files
committed
Android deeplink sends fragment as well
1 parent 263525b commit 23cf9be

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,14 @@ private String maybeGetInitialRouteFromIntent(Intent intent) {
405405
if (host.shouldHandleDeeplinking()) {
406406
Uri data = intent.getData();
407407
if (data != null && !data.getPath().isEmpty()) {
408-
String pathAndQuery = data.getPath();
408+
String pathAndQueryAndFragment = data.getPath();
409409
if (data.getQuery() != null && !data.getQuery().isEmpty()) {
410-
pathAndQuery += "?" + data.getQuery();
410+
pathAndQueryAndFragment += "?" + data.getQuery();
411411
}
412-
return pathAndQuery;
412+
if (data.getFragment() != null && !data.getFragment().isEmpty()) {
413+
pathAndQueryAndFragment += "#" + data.getFragment();
414+
}
415+
return pathAndQueryAndFragment;
413416
}
414417
}
415418
return null;

shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() {
433433
public void
434434
itSendsInitialRouteFromIntentOnStartIfNoInitialRouteFromActivityAndShouldHandleDeeplinking() {
435435
Intent intent = FlutterActivity.createDefaultIntent(RuntimeEnvironment.application);
436-
intent.setData(Uri.parse("http://myApp/custom/route?query=test"));
436+
intent.setData(Uri.parse("http://myApp/custom/route?query=test#fragment"));
437437

438438
ActivityController<FlutterActivity> activityController =
439439
Robolectric.buildActivity(FlutterActivity.class, intent);
@@ -453,7 +453,7 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() {
453453

454454
// Verify that the navigation channel was given the initial route message.
455455
verify(mockFlutterEngine.getNavigationChannel(), times(1))
456-
.setInitialRoute("/custom/route?query=test");
456+
.setInitialRoute("/custom/route?query=test#fragment");
457457
}
458458

459459
@Test
@@ -518,13 +518,14 @@ public void itSendsPushRouteMessageWhenOnNewIntent() {
518518
delegate.onAttach(RuntimeEnvironment.application);
519519

520520
Intent mockIntent = mock(Intent.class);
521-
when(mockIntent.getData()).thenReturn(Uri.parse("http://myApp/custom/route?query=test"));
521+
when(mockIntent.getData())
522+
.thenReturn(Uri.parse("http://myApp/custom/route?query=test#fragment"));
522523
// Emulate the host and call the method that we expect to be forwarded.
523524
delegate.onNewIntent(mockIntent);
524525

525526
// Verify that the navigation channel was given the push route message.
526527
verify(mockFlutterEngine.getNavigationChannel(), times(1))
527-
.pushRoute("/custom/route?query=test");
528+
.pushRoute("/custom/route?query=test#fragment");
528529
}
529530

530531
@Test

0 commit comments

Comments
 (0)