0

So I am currently trying to learn the android webview but have run into some issues. I got it to load youtube.com perfectly but when I try my website it will not work; I just get a blank white screen. Why is that? My website does not have https and this is my code inside the activity's .java class:

    web = new WebView(this);
    web.loadUrl("nickhulsey.com");
    web.getSettings().setJavaScriptEnabled(true);
    web.setWebChromeClient(new WebChromeClient());
    web.setWebViewClient(new WebViewClient());

    setContentView(web);

Is it some sort of security issue or is my website not built properly for the webview to work?

2 Answers 2

2

Use an absolute URL:

web.loadUrl("http://nickhulsey.com/");
0

I hope this will help and it is a minimal better practice to implement webview...

public class MainActivity extends Activity  {

  private WebView wv1;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);

     wv1=(WebView)findViewById(R.id.webView);
     wv1.setWebViewClient(new MyClient());

     String url = "http://nickhulsey.com/";

        wv1.getSettings().setLoadsImagesAutomatically(true);
        wv1.getSettings().setJavaScriptEnabled(true);
        wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        wv1.loadUrl(url);
     }
  });
  }

  private class MyClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
      view.loadUrl(url);
      return true;
    }
   }

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.