Created
January 30, 2013 15:06
-
-
Save charlieCollins/4673868 to your computer and use it in GitHub Desktop.
WebView test/example for 4.2.1.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/