Is there a way to set the WebView to have:

Do not track

option like Chrome app?

有帮助吗?

解决方案

"Do not track" is actually an HTTP header (DNT). So you should be able to do this by adding that header to every request by way of loadUrl(url, headers). For example:

webView.setWebViewClient(new WebViewClient()
{
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        HashMap<String, String> extraHeaders = new HashMap<String, String>();
        extraHeaders.put("DNT", "1");
        view.loadUrl(url, extraHeaders); 
        return true;
    } 
});

Note that this loadUrl() overload requires API level 8.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top