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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With