Android webview is not working in mobile data

1.5k views Asked by At

In my app I have a webView, this webView works perfectly in several devices with varieties of OS but it only works in wifi . If I turn off wifi and turn on mobile data, webView doesn't load anything . Here is my code I used for webview .

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
           webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        } else {
           webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setAllowContentAccess(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setDatabaseEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(false);
        webView.getSettings().setUseWideViewPort(true);
        webView.setWebViewClient(new MyWebViewClient());
        webView.loadUrl(url); 
1

There are 1 answers

0
ZeroOne On

it may cause of internet problem or link is not valid

try to implement onReceivedError to see whether any error occured while load the url

webView.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
    }

    @SuppressWarnings("deprecation")
    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        Log.e(TAG,errorCode + " : " + description + " at " + failingUrl);
    }
});