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

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.