Intercept and override HTTP requests from WebView

后端 未结 7 766
醉话见心
醉话见心 2020-11-30 17:54

I have a WebView in my application in which some site is opened (always the same, it is my own page). The site has some JS code which loads some images from the remote host.

7条回答
  •  [愿得一人]
    2020-11-30 18:02

    Try this, I've used it in a personal wiki-like app:

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("foo://")) {
                // magic
                return true;
            }
            return false;
        }
    });
    

提交回复
热议问题