I\'m new in android development and I am trying out the WebView example in the official android site.
http://developer.android.com/guide/tutorials/views/hello-webvie
Sorry about that – that link is a bit outdated. The fixed version of this tutorial is available here:
http://developer.android.com/guide/webapps/webview.html
We should remove the old link; I'll file a bug.
And note, the error is that setContentView
isn't being called.
webview_id = (WebView)findViewById(R.id.webview_id);
webview_id.getSettings().setJavaScriptEnabled(true); // enable javascript
WebSettings webSettings = webview_id.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setJavaScriptEnabled(true);
webview_id.setInitialScale(90);
webSettings.setLoadWithOverviewMode(true);
webview_id.requestFocusFromTouch();
webview_id.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Snackbar.with(getApplicationContext()).dismiss();
Snackbar.with(getApplicationContext()) // context
.text(description) // text to display
.show(MainActivity.this);
}
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
}
});
if(isNetworkAvailable()){
webview_id .loadUrl("http://helloworld.org/");
}else{
Snackbar.with(getApplicationContext()).dismiss();
Snackbar.with(getApplicationContext()) // context
.text("Please Check your Internet Connection") // text to display
.show(MainActivity.this);
progressBar.setVisibility(View.VISIBLE);
}
}
in oncreate method add WebView.enablePlatformNotifications();
in manifest file add
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
now it works fine...