Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, it is possible to deactivate certain links on a webpage in Android Studio's WebView. One approach is to intercept the WebView's URL loading process and selectively block the links that you want to deactivate. This can be achieved by subclassing the WebViewClient class and overriding the shouldOverrideUrlLoading() method. In this method, you can check the URL being loaded and return true to block the loading if it matches one of the deactivated links.

Here's an example code snippet that demonstrates how to block loading of links to Telegram, Instagram, and Email:

webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.startsWith("mailto:") || url.contains("tel:") || url.contains("instagram.com") ||
                url.contains("telegram.org") || url.contains("t.me")) {
            // Block loading of email, telephone, Instagram, and Telegram links
            return true;
        } else {
            // Allow loading of all other links
            return super.shouldOverrideUrlLoading(view, url);
        }
    }
});

Note that this approach will only block clicks on links in the WebView. Users can still access these links by typing the URL directly in the address bar.