flutter deep linking don't work on a real device
Asked Answered
D

1

7

I'm trying to add deep linking to my app, i'm using uni_links

I followed the instructions on the page, and on android emulator everything works fine- I open the app through the deep link, the snapshot has data and the urlResponse is returned, but on a real device, when I open the app through the deep link, the snapshot doesn't have any data and the HomePage is returned.

here is my code:

    class MyApp extends StatelessWidget {
          @override
          Widget build(BuildContext context) {
            return MaterialApp(
              debugShowCheckedModeBanner: false,
              theme: ThemeData(
                primaryColor: Colors.white,
                visualDensity: VisualDensity.adaptivePlatformDensity,
              ),
              home: StreamBuilder(
                stream: getLinksStream(),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    // our app started by configured links
                    Uri uri = Uri.parse(snapshot.data);
                    List<MapEntry<String, List<String>>> list =
                        uri.queryParametersAll.entries.toList();
                    return urlResponse(uri, list);
                  } else {
                    // our app started regularly
                    return HomePage();
                  }
                },
              ),
            );
          }

and my AndroidManifest.xml:

    <!-- Deep Links -->
        <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
          <data
            android:scheme="http"
            android:host="example.com"
            android:pathPrefix="/myApp"/>
        </intent-filter>

Can anyone help me to understand why it's working on emulator but not on a real device?

Deceleron answered 10/2, 2021 at 12:17 Comment(0)
C
0

In the package page the author says "Usually you would check the getInitialLink and also listen for changes." It maybe the case that when you tried on android emulator you had the app in the background but when you tried with a real device the app wasn't open. Try out the example code the author got, and if the problem persists report the issue in his github page.

The thing about these links is that just by having the intent-filter the app would open even if you didn't have any dart code. So it maybe a little confusing when the app launches, but the data is not shown. I would try getInitialLink.

Chaille answered 11/2, 2021 at 14:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.