WebView isn't opening my me web but in browser works

I read a lot of posts like this here, but didn't work for me...

It always shows me "Webpage not available"

activity.java

    package ar.com.liit.datawarehouse;

    import ar.com.liit.datawarehouse.util.SystemUiHider;

    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.view.View;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;

    public class FullscreenActivity extends Activity {

        private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
        private SystemUiHider mSystemUiHider;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_fullscreen);
            final View contentView = findViewById(R.id.fullscreen_content);
            mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
            mSystemUiHider.setup();
        }

        @SuppressLint("SetJavaScriptEnabled")
        @Override
        protected void onPostCreate(Bundle savedInstanceState) {
            super.onPostCreate(savedInstanceState);
            delayedHide(100);
            final WebView wBrowser = (WebView) findViewById(R.id.webView1);
            wBrowser.getSettings().setJavaScriptEnabled(true);
            wBrowser.loadUrl("https://liit.com.ar/");
            wBrowser.setWebViewClient(new WebViewClient() {
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                    wBrowser.loadUrl("https://www.google.com/");
                }
            });
        }
        Handler mHideHandler = new Handler();
        Runnable mHideRunnable = new Runnable() {
            @Override
            public void run() {
                mSystemUiHider.hide();
            }
        };
        private void delayedHide(int delayMillis) {
            mHideHandler.removeCallbacks(mHideRunnable);
            mHideHandler.postDelayed(mHideRunnable, delayMillis);
        }
    }

manifest

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="ar.com.liit.datawarehouse"
        android:versionCode="1"
        android:versionName="1.0" >
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-sdk
            android:minSdkVersion="14"
            android:targetSdkVersion="17" />
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" 
            android:hardwareAccelerated="true">
            <activity
                android:name="ar.com.liit.datawarehouse.FullscreenActivity"
                android:configChanges="orientation|keyboardHidden|screenSize"
                android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>

    </manifest>

layout

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#0099cc"
        tools:context=".FullscreenActivity" >

        <!--
             The primary full-screen view. This can be replaced with whatever view
             is needed to present your content, e.g. VideoView, SurfaceView,
             TextureView, etc.
        -->

        <TextView
            android:id="@+id/fullscreen_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:keepScreenOn="true"
            android:text="@string/dummy_content"
            android:textColor="#33b5e5"
            android:textSize="50sp"
            android:textStyle="bold" />

        <!--
             This FrameLayout insets its children based on system windows using
             android:fitsSystemWindows.
        -->

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true" >

            <WebView
                android:id="@+id/webView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </FrameLayout>

    </FrameLayout>

Upvotes: 0

Views: 87

Answers (1)

Blackbelt
Blackbelt

Reputation: 157487

it seems to be a well know "issue". The "fix" would be to override WebViewClient.onReceivedSslError, and use handler.proceed()

Upvotes: 2

Related Questions