public
Created

WebView test/example for 4.2.1.

  • Download Gist
WebViewTest
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
package com.totsp.webviewtest;
 
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
 
public class MainActivity extends Activity {
 
private static final String TAG = "WebViewTest";
 
private WebView webview;
 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView) findViewById(R.id.webview);
loadWebview();
}
 
private void loadWebview() {
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
Log.d(TAG, "onPageFinished url:" + url);
}
 
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d(TAG, "shouldOverrideUrlLoading");
return false;
}
 
@Override
public void onPageStarted(WebView view, String url, android.graphics.Bitmap favicon) {
Log.d(TAG, "onPageStarted url:" + url);
}
 
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.d(TAG, "onRecievedError code:" + errorCode + " desc:" + description + " failingUrl:" + failingUrl);
}
});
 
Log.d(TAG, "******************* LOAD URL...");
webview.loadUrl("http://www.google.com");
}
 
}

Logging works as expected, and WebView loads the URL as expected.

D/WebViewTest( 3502): onPageStarted url:http://www.google.com/
I/ActivityManager( 583): Displayed com.totsp.webviewtest/.MainActivity: +466ms
D/WebViewTest( 3502): onPageFinished url:http://www.google.com/

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.