1

I'm setting up a url https://turnbackhoax.id/ inside a WebView. But the WebView is just showing a blank page. I have tried to set other URLs and those work. I've learned and searched for a similar problem but nothing changed.

Following is my WebView code:

public class LaporPage extends AppCompatActivity {

    private WebView webV;
    Activity activity;
    private ProgressDialog progDailog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lapor_page);

        activity = this;

        progDailog = ProgressDialog.show(activity, "Loading","Please wait...", true);
        progDailog.setCancelable(false);

        webV = (WebView) findViewById(R.id.web_view);

        webV.getSettings().setDomStorageEnabled(true);
        webV.getSettings().setJavaScriptEnabled(true);
        webV.getSettings().setLoadWithOverviewMode(true);
        webV.getSettings().setUseWideViewPort(true);
        webV.setWebChromeClient(new WebChromeClient());
        webV.setWebViewClient(new WebViewClient(){

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                progDailog.show();
                view.loadUrl(url);
                return true;
            }
            @Override
            public void onPageFinished(WebView view, final String url) {
                progDailog.dismiss();
            }
        });
        webV.loadUrl("https://turnbackhoax.id/");
    }
}
Ren
  • 11
  • 1
  • 5

6 Answers6

2

I have checked the URL, it is throwing an SSL handshake error in the web view. Although it's not a good practice to ignore the SSL error but this will solve your problem

webview.setWebViewClient(new WebViewClient(){

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler,SslError error) {
        handler.proceed();
    }


});
Lakhwinder Singh
  • 6,799
  • 4
  • 25
  • 42
1

Its simple and Exact Solution is to enable the DomStorage & set setJavaScriptCanOpenWindowsAutomatically = true

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

    webView.getSettings().setDomStorageEnabled(true);    // this 
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);  //and this

It will solve the problem.

Enjoy it.

Sheharyar Ejaz
  • 2,808
  • 1
  • 14
  • 15
0

Add this permission under your Manifest.xml

  <uses-permission android:name="android.permission.INTERNET" />

Use this:

 wv = (WebView) findViewById(R.id.web_view);
        wv.setInitialScale(1);      //webview page matches the screen size.
        wv.getSettings().setLoadWithOverviewMode(true);
        wv.getSettings().setUseWideViewPort(true);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);    //loads online website when no internet connection.
        wv.loadUrl("https://prajwalwaingankar.wixsite.com/nivala");
Prajwal Waingankar
  • 2,534
  • 2
  • 13
  • 20
0

You need to use override onReceivedSslError

Try this

webV.setWebViewClient(new WebViewClient(){

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            progDailog.show();
            view.loadUrl(url);

            return true;
        }
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler,
                                       SslError error) {
            handler.proceed();
        }
        @Override
        public void onPageFinished(WebView view, final String url) {
            progDailog.dismiss();
        }

    });
Bunny
  • 1,044
  • 12
  • 23
0

create file called network_security_config.xml,

<network-security-config>
<base-config cleartextTrafficPermitted="true">
    <debug-overrides>
    <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
    </debug-overrides>
</base-config>
<domain-config>
    <domain includeSubdomains="true">example.com</domain>
    <domain includeSubdomains="true">example.example.com</domain>
    <trust-anchors>
        <certificates src="@raw/mycert" />
        <certificates src="system" />
    </trust-anchors>
</domain-config>

In Manifest,

<application ..... 
android:networkSecurityConfig="@xml/network_security_config"

</application>

and add your SSL if required

0

To properly handle SSL certificate validation and avoid application rejection from Google according to new Security Policy, Change your code to invoke SslErrorHandler.proceed() whenever the certificate presented by the server meets your expectations, and invoke SslErrorHandler.cancel()

webV.setWebViewClient(new  WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
                webV!!.loadUrl(url)
                return true
            }

            override fun onReceivedSslError(
                view: WebView, handler: SslErrorHandler,
                error: SslError
            ) {
                handler.proceed()
            }
        });
Jane Alam
  • 360
  • 2
  • 7