9

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?

8
  • 3
    did you add internet permission in manifest file? uses-permission android:name="android.permission.INTERNET"></uses-permission> Commented Nov 17, 2014 at 4:48
  • Yes, I have added internet permission Commented Nov 17, 2014 at 4:52
  • 1
    You sure ur getting correct URL in url string? Commented Nov 17, 2014 at 4:53
  • Check your URL start withhttp:// or https:// Commented Nov 17, 2014 at 4:53
  • Yes, it starts with https:// Commented Nov 17, 2014 at 5:14

2 Answers 2

30

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Beware. Applications or updates using this approach will be rejected in Google Play. See this post.
@kibitzerCZ - Yup, I am aware of that. Google asks for showing a warning message for using self-signed SSL certificates.
3

Make sure the url string you're loading has "www" prefixed to it, i.e. "https://www.google.com" and not "https://google.com"

Weirdly enough, this fixed the issue, at least on my end.

1 Comment

This worked for me too, specifically with this exact URL. Wonder why.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.