0

My webview loads the URL which I load on to it in both Android emulator and device (using 3G).

When I load the same web page with wifi it returns a blank/white page.

    mWebView = (WebView) mRootView.findViewById(R.id.webView);

    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setRenderPriority(RenderPriority.HIGH);

    mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

    mWebView.setWebViewClient(new WebViewClient() 
        @Override
        public void onPageFinished(WebView view, String url) {

            Log.d(TAG, "Finished loading URL: " + url);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {

            Log.d("ON RECEIVE ERROR", failingUrl + " --- " + description);

        }       })
    mWebView.invalidate();
        mWebView.loadUrl(Url);

And I have done any changes/added something in manifest for this.

This is my manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tfe"
    android:versionCode="3"
    android:versionName="0.0.3" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <permission
        android:name="com.xxx.gcm.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.xxx.gcm.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:name=".application.SampleApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".HomeActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
    </application>

</manifest>
halfer
  • 19,824
  • 17
  • 99
  • 186
ydnas
  • 519
  • 1
  • 12
  • 29

2 Answers2

2

Please add

@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) 
{
handler.proceed(); // Ignore SSL certificate errors
}

inside setWebViewClient.

Neha Shukla
  • 3,572
  • 5
  • 38
  • 69
1

There are possible reasons causing "WebView goes blank after finish loading page":

  1. If your WebView part defined in the layout xml file has dimensions like

    android:layout_width="wrap_content"
    
    or
    android:layout_height="wrap_content"
    

    Then after the page is loaded, the content is defined and WebView tries to "wrap" it, thus in some cases reduces the view's dimensions into 0dp and make your WebView invisible. Solution: change all those into fill_parent

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    
  2. This may be caused by an SSL certification error. Try this:

    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed();
    }
    
    
Mr. Kro
  • 138
  • 9