Reputation: 33
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?
Upvotes: 0
Views: 188
Reputation: 10622
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;
}
}
Upvotes: 0