WebView browser;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
browser = (WebView) findViewById(R.id.webve);
browser.getSettings().setJavaScriptEnabled(true);
browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
browser.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url)
{
browser.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
}
});
browser.loadUrl("http://www.google.com");
}
final Context myApp = this;
Builder builder;
String content_html;
class MyJavaScriptInterface
{
@SuppressWarnings("unused")
public void showHTML(String html)
{
builder = new AlertDialog.Builder(myApp);
builder.setTitle("HTML")
.setMessage(html)
.setPositiveButton(android.R.string.ok, null)
.setCancelable(false)
.create()
.show();
content_html = html;
Log.i("html", html+" ");
}
}
這個代碼在機器人2.2正常工作但不工作Android 2.3及以上...給,以下顯示的錯誤信息..這個代碼在機器人2.2正常工作但不工作Android 2.3及以上
12-19 14:53:33.786: W/dalvikvm(452): JNI WARNING: jarray 0x40543998 points to non-array object (Ljava/lang/String;)
12-19 14:53:33.831: I/dalvikvm(452): "WebViewCoreThread" prio=5 tid=9 NATIVE
12-19 14:53:33.838: I/dalvikvm(452): | group="main" sCount=0 dsCount=0 obj=0x4051e198 self=0x29b650
12-19 14:53:33.838: I/dalvikvm(452): | sysTid=460 nice=0 sched=0/0 cgrp=default handle=2733960
12-19 14:53:33.858: I/dalvikvm(452): | schedstat=(2873090555 2669702962 182)
12-19 14:53:33.878: I/dalvikvm(452): at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
12-19 14:53:33.885: I/dalvikvm(452): at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
12-19 14:53:33.905: I/dalvikvm(452): at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:246)
12-19 14:53:33.924: I/dalvikvm(452): at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1570)
12-19 14:53:33.924: I/dalvikvm(452): at android.webkit.WebViewCore.access$1400(WebViewCore.java:53)
12-19 14:53:33.934: I/dalvikvm(452): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:956)
12-19 14:53:33.955: I/dalvikvm(452): at android.os.Handler.dispatchMessage(Handler.java:99)
12-19 14:53:33.955: I/dalvikvm(452): at android.os.Looper.loop(Looper.java:130)
12-19 14:53:33.955: I/dalvikvm(452): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629)
12-19 14:53:33.955: I/dalvikvm(452): at java.lang.Thread.run(Thread.java:1019)
12-19 14:53:33.964: E/dalvikvm(452): VM aborting