Ask Your Question
0

How can the opening of installed apps by clicking on a link be prevented in Webview?

asked 2022-05-25 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-03 18:00:00 +0000

qstack gravatar image

One way to prevent the opening of installed apps by clicking on a link in Webview is to disable the deep linking feature. This can be done by implementing a custom WebViewClient and overriding the shouldOverrideUrlLoading method.

Here is an example code snippet to disable deep linking:

webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // Check if the URL is a deep link
        if (url.startsWith("intent://") || url.startsWith("market://")) {
            // Return true to prevent the app from opening the link
            return true;
        } else {
            // Return false to allow the link to be opened normally in the WebView
            return false;
        }
    }
});

In the above example, we check if the URL is a deep link (starting with "intent://" or "market://"). If it is, we return true to prevent the app from opening the link. If it's a regular link, we return false to allow it to be opened normally in the WebView.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-25 11:00:00 +0000

Seen: 8 times

Last updated: May 03 '21