1), Html页面设计:
<html>
<head>
</head>
<body>
<script type="text/javascript">
if (window.devicePixelRatio) { //If WebKit browser
var st = escape(navigator.javaEnabled.toString());
if (st === 'function%20javaEnabled%28%29%20%7B%20%5Bnative%20code%5D%20%7D') {
document.write('V8 detected');
} else {
document.write('JSC detected');
}
} else {
document.write("Not a WebKit browser");
}
</script>
</body>
</html>
2),Activity设计
package com.tutor.webwiewdemo;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.util.Log;
public class WebViewDemo extends Activity {
private WebView mWebView;
private Button mButton;
public String TAG="WebViewDemo";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
WebSettings mWebSettings = mWebView.getSettings();
mWebSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/v8jsctest.html");
}
}
3),layout设计
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="160dip"
android:layout_height="wrap_content"
android:text="V8 or JSC test:"
/>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<!--
Button
android:id="@+id/button"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Change the webview content"
-->
</LinearLayout>

这篇博客介绍了如何在Android中使用WebView来判断设备上的JavaScript引擎是V8还是JavaScriptCore。通过编写特定的JavaScript代码并结合WebView加载HTML页面,来检测浏览器内核。在Activity中设置WebView并加载含有检测代码的HTML文件,布局文件包含一个WebView展示检测结果。
895

被折叠的 条评论
为什么被折叠?



