1

I am building a web application, and I would like my app to open app links.

However, I am having trouble determining if a url is an app link or a regular url.

Just like how chrome does, I would like my app to navigate within the app if the url is not an app link or deep link, but my current method opens all urls in external browser if it isn't from a specified host.

public boolean shouldOverrideUrlLoading(WebView view, String url) {
    String host = null;
    try {
        URI u = new URI(url);
        host = u.getHost();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    if (host == null || !host.contains("example.com")) {
        try {
            onActivity.startActivity(Intent.parseUri(url, Intent.URI_INTENT_SCHEME));
            return true;
        } catch (ActivityNotFoundException | URISyntaxException e) {
            e.printStackTrace();
        }
    }
}

Is there a way that I can distinguish the behavior of app link navigation and plan url navigation?

Thanks

IChung
  • 347
  • 1
  • 3
  • 8

1 Answers1

2

Although it was not the exact behavior I was expecting, I had find something similar.

In case anyone is interested on executing outside app with startActivity(url_intent) but not in a browser, by adding

intent.setFlags(Intent.FLAG_ACTIVITY_REQUIRE_NON_BROWSER);

you can disregard executions of application that contains

<intent-filter>
        <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9

IChung
  • 347
  • 1
  • 3
  • 8