Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webview doesn't load the URL , but browser does

So from my first screen I am passing a URL to an activity to launch in webview. But when webview is launched , it shows "web page not available - The web page at URL might be temporarily down or it may have moved permanently to a new web address"

But when i launch the same URL in android browser, it works fine. Here is my code for launching that URL in webview

    super.onCreate(savedInstanceState);

    String url = "";
    url = getIntent().getStringExtra("loginURL");
    WebView urlWebView = new WebView(this);
    urlWebView.setWebViewClient(new WebViewClient());

    urlWebView.getSettings().setJavaScriptEnabled(true);
    urlWebView.loadUrl(url);
    this.setContentView(urlWebView);

What am I doing wrong?

like image 206
yogsma Avatar asked Nov 17 '14 04:11

yogsma


Video Answer


1 Answers

I found the issue. The issue was that the URL I was using has https:// and SSL certificate for the URL was self-signed. The solution from Does the Web View on Android support SSL? helped me fixed the issue.

I added below part in my code

import android.net.http.*; //added this import statement

urlWebView.setWebViewClient(new WebViewClient(){

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

Hope this will help other users.

like image 195
yogsma Avatar answered Oct 13 '22 07:10

yogsma