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

Commit cfb085c

Browse files
committed
Android sends push route when onNewIntent
1 parent 818dcc3 commit cfb085c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.app.Activity;
1010
import android.content.Context;
1111
import android.content.Intent;
12+
import android.net.Uri;
1213
import android.os.Build;
1314
import android.os.Bundle;
1415
import android.view.LayoutInflater;
@@ -622,8 +623,12 @@ void onRequestPermissionsResult(
622623
void onNewIntent(@NonNull Intent intent) {
623624
ensureAlive();
624625
if (flutterEngine != null) {
625-
Log.v(TAG, "Forwarding onNewIntent() to FlutterEngine.");
626+
Log.v(TAG, "Forwarding onNewIntent() to FlutterEngine and sending pushRoute message.");
626627
flutterEngine.getActivityControlSurface().onNewIntent(intent);
628+
Uri data = intent.getData();
629+
if (data != null && !data.toString().isEmpty()) {
630+
flutterEngine.getNavigationChannel().pushRoute(intent.getData().toString());
631+
}
627632
} else {
628633
Log.w(TAG, "onNewIntent() invoked before FlutterFragment was attached to an Activity.");
629634
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import android.app.Activity;
1616
import android.content.Context;
1717
import android.content.Intent;
18+
import android.net.Uri;
1819
import androidx.annotation.NonNull;
1920
import androidx.lifecycle.Lifecycle;
2021
import io.flutter.FlutterInjector;
@@ -426,6 +427,25 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() {
426427
.onRequestPermissionsResult(any(Integer.class), any(String[].class), any(int[].class));
427428
}
428429

430+
@Test
431+
public void itSendsPushRouteMessageWhenOnNewIntent() {
432+
// Create the real object that we're testing.
433+
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
434+
435+
// --- Execute the behavior under test ---
436+
// The FlutterEngine is setup in onAttach().
437+
delegate.onAttach(RuntimeEnvironment.application);
438+
439+
Intent mockIntent = mock(Intent.class);
440+
when(mockIntent.getData()).thenReturn(Uri.parse("http://myApp/custom/route"));
441+
// Emulate the host and call the method that we expect to be forwarded.
442+
delegate.onNewIntent(mockIntent);
443+
444+
// Verify that the navigation channel was given the push route message.
445+
verify(mockFlutterEngine.getNavigationChannel(), times(1))
446+
.pushRoute("http://myApp/custom/route");
447+
}
448+
429449
@Test
430450
public void itForwardsOnNewIntentToFlutterEngine() {
431451
// Create the real object that we're testing.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import org.junit.Before;
2121
import org.junit.Test;
2222
import org.junit.runner.RunWith;
23-
import org.robolectric.android.controller.ActivityController;
2423
import org.robolectric.Robolectric;
2524
import org.robolectric.RobolectricTestRunner;
2625
import org.robolectric.RuntimeEnvironment;
26+
import org.robolectric.android.controller.ActivityController;
2727
import org.robolectric.annotation.Config;
2828

2929
@Config(manifest = Config.NONE)

0 commit comments

Comments
 (0)