Skip to content

[Android] Flutter does not get the correct initial route when launch by a deep link  #121244

@chunhtai

Description

@chunhtai

b/270298884

Follow the Android section of https://docs.flutter.dev/development/ui/navigation/deep-linking

If the deeplink is launched when the app is not open, it will launch with the default initial route / instead of the deeplinked route.

repro:

  1. create a flutter app
main.dart
import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
  routes: <String, WidgetBuilder> {
    '/': (_)=> Scaffold(appBar: AppBar(title: Text('/'))),
    '/abc': (_)=> Scaffold(appBar: AppBar(title: Text('/abc'))),
  }
));
  1. in /android/app/src/main/AndroidManifest.xml, add following meta tags in
xml
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" android:host="flutterbooksample.com" />
    <data android:scheme="https" />
</intent-filter>
  1. do a flutter run on any Android device (I am using motoG4)
  2. force quit the app, and make sure the app is not in the background.
  3. run adb command
adb shell 'am start -a android.intent.action.VIEW \
    -c android.intent.category.BROWSABLE \
    -d "http://flutterbooksample.com/abc"' \
    <package name>

expect: the page is opened with /abc in the appbar
actual: the page is opened with / in the appbar

This only happen if the app is started cold, if the app is in the background the deeplink command will work correctly.

Metadata

Metadata

Labels

P0Critical issues such as a build break or regressionplatform-androidAndroid applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions