Infinite loop with Android App Links (deep links) in Flutter

1k views Asked by At

Currently we've got a problem with our Flutter app and deep links (or App Links and Universal Links). On iOS everything is working, but on Android we've get an infinite loop on certain links.

The app can be opened via deep links and we can display content based on these links (We're using the package uni_links2). However, we have a big problem with outgoing links in the app.

Our app has a details page and links with the same domain appear here, but they should be opened in the browser and not in the app. The links go to content that we can't handle in the app.

These links should be opened within the app from the deep link:

An url like this should be opened within the browser:

AndroidManifest.xml

<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="ourdomain.com" />
    <data android:scheme="http" android:host="www.ourdomain.com" />
    <data android:scheme="https" />
</intent-filter>

With the url_launcher package I can open urls, but they are directly seen as deep links and opened again in our own app. I also tried android_intent, and it's working when define Chrome as the default intent.

AndroidIntent intent = AndroidIntent(
  action: 'action_view',
  data: url,
  package: 'com.android.chrome',
);
await intent.launch();

But I can't guarantee that the user has Chrome installed.

Currently I have no idea how to solve this issue. All I know is that I can specify whole domains or paths as the schema. Unfortunately, I cannot exclude specific paths. Also, I don't know how to specify that links should open in the browser and not in our app.

Do you have any idea how I can fix the problem? Thanks in advance!

1

There are 1 answers

0
shanraisshan On
<data android:scheme="http" android:host="ourdomain.com" />
<data android:scheme="http" android:host="www.ourdomain.com" />

Since you have not defined any pathPattern or pathPrefix, all the links of www.ourdomain.com will open your app.

To specify which links to include, you should read about pathPatterns, a simple example can be

<data android:scheme="http" android:host="ourdomain.com" android:pathPattern=".*category.*"/>

LINKS - THAT WILL OPEN IN APP

This will open all the links containing the word category

https://www.ourdomain.com/category
https://www.ourdomain.com/category/abc
https://www.ourdomain.com/abc/category
https://www.ourdomain.com/abc/category/xyz

LINKS - THAT WILL NOT OPEN IN APP

https://www.ourdomain.com/categry
https://www.ourdomain.com/categry/abc