关于android webview js里HTML5的地理位置定位,在别

WebView处理网页位置请求
发表于 日 17:23 | Hits: 7452
随着移动设备的激增,LBS(Location Based Service)已然成为趋势,其最关键的还是获取设备的位置信息。native代码获取位置信息轻轻松松可以搞定,实际上网页获取位置信息也不是那么困难。
在HTML5中,提供了一套定位用户信息的接口,当然这个位置信息是通过客户端,准确说是浏览器获取的。
注意,位置信息属于个人隐私的范围,只有经过用户同意之后才能获取到信息。
网页如何实现请求位置信息
使用getCurrentPosition()方法来请求位置信息。
下面是一个很简单的示例,来展示用户位置信息的经度和纬度。
lineos:false1
&!DOCTYPE html&
&p id=&demo&&Click the button to get your coordinates:&/p&
&button onclick=&getLocation()&&Try It&/button&
var x = document.getElementById(&demo&);
function getLocation() {
(&getLocation working&)
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition,showError);
x.innerHTML = &Geolocation is not supported by this browser.&;
function showPosition(position) {
x.innerHTML=&Latitude: & + position.coords.latitude + &&br&Longitude: & + position.coords.
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = &User denied the request for Geolocation.&
case error.POSITION_UNAVAILABLE:
x.innerHTML = &Location information is unavailable.&
case error.TIMEOUT:
x.innerHTML = &The request to get user location timed out.&
case error.UNKNOWN_ERROR:
x.innerHTML = &An unknown error occurred.&
检测getLocation方法是否可用
如果可以调用getCurrentPosition方法,否则提示浏览器不支持
如果getCurrentPosition获取信息成功,返回一个坐标系的对象,并将这个对象作为参数传递到showPosition方法,如果失败,调用showError方法,并将错误码作为showError方法的参数。
showPosition方法展示经度和纬度信息
showError方法用来处理请求错误
上述部分参考自,更多高级操作请访问左侧链接。
WebView如何返回给网页
大致操作步骤
在manifest中申请android.permission.ACCESS_FINE_LOCATION 或 android.permission.ACCESS_COARSE_LOCATION 权限。两者都有更好。
设置webivew开启javascript功能,地理定位功能,设置物理定位数据库路径
在onGeolocationPermissionsShowPrompt处理物理位置请求,常用的是提示用户,让用户决定是否允许。
android.permission.ACCESS_FINE_LOCATION 通过GPS,基站,Wifi等获取精确的
位置信息。
android.permission.ACCESS_COARSE_LOCATION 通过基站,Wifi等获取错略的
位置信息。
onGeolocationPermissionsShowPrompt 位置信息请求回调,通常在这里弹出选择是否赋予权限的对话框
GeolocationPermissions.Callback.invoke(String origin, boolean allow, boolean remember)决定是否真正提供给网页信息,可根据用户的选择结果选择处理。实现代码
lineos:false1
final WebView webView = new WebView(this);
addContentView(webView,
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setGeolocationEnabled(true);
settings.setGeolocationDatabasePath(getFilesDir().getPath());
webView.setWebChromeClient(new WebChromeClient() {
public void onGeolocationPermissionsHidePrompt() {
super.onGeolocationPermissionsHidePrompt();
Log.i(LOGTAG, &onGeolocationPermissionsHidePrompt&);
public void onGeolocationPermissionsShowPrompt(final String origin,
final Callback callback) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage(&Allow to access location information?&);
OnClickListener dialogButtonOnClickListener = new OnClickListener() {
public void onClick(DialogInterface dialog, int clickedButton) {
if (DialogInterface.BUTTON_POSITIVE == clickedButton) {
callback.invoke(origin, true, true);
} else if (DialogInterface.BUTTON_NEGATIVE == clickedButton) {
callback.invoke(origin, false, false);
builder.setPositiveButton(&Allow&, dialogButtonOnClickListener);
builder.setNegativeButton(&Deny&, dialogButtonOnClickListener);
builder.show();
super.onGeolocationPermissionsShowPrompt(origin, callback);
Log.i(LOGTAG, &onGeolocationPermissionsShowPrompt&);
webView.loadUrl(&file:///android_asset/geolocation.html&);
I/SqliteDatabaseCpp(21863): sqlite returned: error code = 14
原因是你没有设置setGeolocationDatabasePath,按照上面例子设置即可。
点击之后没有任何变化
检查代码是否按照上面一样,是否有错误。
在第一次请求的是否,需要的反应时间比较长。
检测定位服务是否可用
当GPS_PROVIDER和NETWORK_PROVIDER有一者可用,定位服务就可以用,当两者都不能用时,即定位服务不可以用。
注意PASSIVE_PROVIDER不能作为定位服务可用的标志。因为这个provider只会返回其他Provider提供的位置信息,自己无法定位。
lineos:false1
private void testGeolocationOK() {
LocationManager manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
boolean gpsProviderOK = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean networkProviderOK = manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
boolean geolocationOK = gpsProviderOK && networkProviderOK;
Log.i(LOGTAG, &gpsProviderOK = & + gpsProviderOK + &; networkProviderOK = & + networkProviderOK + &; geoLocationOK=& + geolocationOK);
跳转到位置设置界面
我们只需要发送一个简单的隐式intent即可启动位置设置界面
lineos:false1
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
评价列表(0)android WebView加载html5介绍
viewport属性放在HTML的meta中接下来看详细代码,感兴趣的你可以参考下本文
Android设备多分辨率的问题
Android浏览器默认预览模式浏览 会缩小页面 WebView中则会以原始大小显示
Android浏览器和WebView默认为mdpi。hdpi相当于mdpi的1.5倍 ldpi相当于0.75倍
三种解决方式:1 viewport属性 2 CSS控制 3 JS控制
1 viewport属性放在HTML的&meta&中
&SPANstyle="FONT-SIZE: x-small"& &head&
&title&Exmaple&/title&
&metaname=”viewport” content=”width=device-width,user-scalable=no”/&
&/head&&/SPAN&
meta中viewport的属性如下
在一个样式表中,指定不同的样式
&metaname="viewport"content="target-densitydpi=device-dpi, width=device-width"/&
Android浏览器和WebView支持查询当前设别密度的DOM特性
window.devicePixelRatio 同样值有3个(0.75,1,1.5对应3种分辨率)
JS中查询设备密度的方法
if (window.devicePixelRatio == 1.5) {
alert("This is a high-density screen");
} elseif (window.devicePixelRation == 0.75) {
alert("This is a low-density screen");
Android中构建HTML5应用
使用WebView控件 与其他控件的使用方法相同 在layout中使用一个&WebView&标签
WebView不包括导航栏,地址栏等完整浏览器功能,只用于显示一个网页
在WebView中加载Web页面,使用loadUrl()
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("");
注意在manifest文件中加入访问互联网的权限:
&uses-permissionandroid:name="android.permission.INTERNET"/&
在Android中点击一个链接,默认是调用应用程序来启动,因此WebView需要代为处理这个动作 通过WebViewClient
//设置WebViewClient
webView.setWebViewClient(new WebViewClient(){
publicboolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
publicvoid onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
publicvoid onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
这个WebViewClient对象是可以自己扩展的,例如
privateclass MyWebViewClient extends WebViewClient {
publicboolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new MyWebViewClient());
另外出于用户习惯上的考虑 需要将WebView表现得更像一个浏览器,也就是需要可以回退历史记录
因此需要覆盖系统的回退键 goBack,goForward可向前向后浏览历史页面
publicboolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack() {
myWebView.goBack();
returnsuper.onKeyDown(keyCode, event);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
(这里的webSetting用处非常大 可以开启很多设置 在之后的本地存储,地理位置等之中都会使用到)
1 在JS中调用Android的函数方法
首先 需要在Android程序中建立接口
finalclass InJavaScript {
publicvoid runOnAndroidJavaScript(final String str) {
handler.post(new Runnable() {
publicvoid run() {
TextView show = (TextView) findViewById(R.id.textview);
show.setText(str);
//把本类的一个实例添加到js的全局对象window中,
//这样就可以使用windows.injs来调用它的方法
webView.addJavascriptInterface(new InJavaScript(), "injs");
在JavaScript中调用Js代码
function sendToAndroid(){
var str = "Cookie call the Android method from js";
windows.injs.runOnAndroidJavaScript(str);//调用android的函数
2 在Android中调用JS的方法
在JS中的方法:
function getFromAndroid(str){
document.getElementByIdx_x_x_x("android").innerHTML=
在Android调用该方法Java代码
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
publicvoid onClick(View arg0) {
//调用javascript中的方法
webView.loadUrl("javascript:getFromAndroid('Cookie call the js function from Android')");
3 Android中处理JS的警告,对话框等 在Android中处理JS的警告,对话框等需要对WebView设置WebChromeClient对象
//设置WebChromeClient
webView.setWebChromeClient(new WebChromeClient(){
//处理javascript中的alert
publicboolean onJsAlert(WebView view, String url, String message, final JsResult result) {
//构建一个Builder来显示网页中的对话框
Builder builder = new Builder(MainActivity.this);
builder.setTitle("Alert");
builder.setMessage(message);
builder.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener() {
publicvoid onClick(DialogInterface dialog, int which) {
result.confirm();
builder.setCancelable(false);
builder.create();
builder.show();
//处理javascript中的confirm
publicboolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
Builder builder = new Builder(MainActivity.this);
builder.setTitle("confirm");
builder.setMessage(message);
builder.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener() {
publicvoid onClick(DialogInterface dialog, int which) {
result.confirm();
builder.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
publicvoid onClick(DialogInterface dialog, int which) {
result.cancel();
builder.setCancelable(false);
builder.create();
builder.show();
//设置网页加载的进度条
publicvoid onProgressChanged(WebView view, int newProgress) {
MainActivity.this.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, newProgress * 100);
super.onProgressChanged(view, newProgress);
//设置应用程序的标题title
publicvoid onReceivedTitle(WebView view, String title) {
MainActivity.this.setTitle(title);
super.onReceivedTitle(view, title);
Android中的调试
通过JS代码输出log信息
Js代码: console.log("Hello World");
Log信息: Console: Hello World /hello.html :82
在WebChromeClient中实现onConsoleMesaage()回调方法,让其在LogCat中打印信息
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebChromeClient(new WebChromeClient() {
publicvoid onConsoleMessage(String message, int lineNumber, String sourceID) {
Log.d("MyApplication", message + " -- From line "
+ lineNumber + " of "
+ sourceID);
以及Java代码
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebChromeClient(new WebChromeClient() {
publicboolean onConsoleMessage(ConsoleMessage cm) {
Log.d("MyApplication", cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId() );
*ConsoleMessage 还包括一个 MessageLevel 表示控制台传递信息类型。 您可以用messageLevel()查询信息级别,以确定信息的严重程度,然后使用适当的Log方法或采取其他适当的措施。
HTML5本地存储在Android中的应用
HTML5提供了2种客户端存储数据新方法: localStorage 没有时间限制 sessionStorage 针对一个Session的数据存储
&script type="text/javascript"&
localStorage.lastname="Smith";
document.write(localStorage.lastname);
&script type="text/javascript"&
sessionStorage.lastname="Smith";
document.write(sessionStorage.lastname);
WebStorage的API:
//清空storage
localStorage.clear();
//设置一个键值
localStorage.setItem(“yarin”,“yangfegnsheng”);
//获取一个键值
localStorage.getItem(“yarin”);
//获取指定下标的键的名称(如同Array)
localStorage.key(0);
//return “fresh” //删除一个键值
localStorage.removeItem(“yarin”);
注意一定要在设置中开启哦
setDomStorageEnabled(true)
在Android中进行操作 Java代码
//启用数据库
webSettings.setDatabaseEnabled(true);
String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
//设置数据库路径
webSettings.setDatabasePath(dir);
//使用localStorage则必须打开
webSettings.setDomStorageEnabled(true);
//扩充数据库的容量(在WebChromeClinet中实现)
publicvoid onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota,
long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(estimatedSize * 2);
在JS中按常规进行数据库操作 Js代码
function initDatabase() {
if (!window.openDatabase) {
alert('Databases are not supported by your browser');
var shortName = 'YARINDB';
var version = '1.0';
var displayName = 'yarin db';
var maxSize = 100000; // in bytes
YARINDB = openDatabase(shortName, version, displayName, maxSize);
createTables();
selectAll();
} catch(e) {
if (e == 2) {
// Version mismatch.
console.log("Invalid database version.");
console.log("Unknown error "+ e +".");
function createTables(){
YARINDB.transaction(
function (transaction) {
transaction.executeSql('CREATE TABLE IF NOT EXISTS yarin(id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL,desc TEXT NOT NULL);', [], nullDataHandler, errorHandler);
insertData();
function insertData(){
YARINDB.transaction(
function (transaction) {
//Starter data when page is initialized
var data = ['1','yarin yang','I am yarin'];
transaction.executeSql("INSERT INTO yarin(id, name, desc) VALUES (?, ?, ?)", [data[0], data[1], data[2]]);
function errorHandler(transaction, error){
if (error.code==1){
// DB Table already exists
// Error is a human-readable string.
console.log('Oops. Error was '+error.message+' (Code '+error.code+')');
function nullDataHandler(){
console.log("SQL Query Succeeded");
function selectAll(){
YARINDB.transaction(
function (transaction) {
transaction.executeSql("SELECT * FROM", [], dataSelectHandler, errorHandler);
function dataSelectHandler(transaction, results){
// Handle the results
for (var i=0; i&results.rows. i++) {
var row = results.rows.item(i);
var newFeature = new Object();
newFeature.name = row['name'];
newFeature.decs = row['desc'];
document.getElementByIdx_x_x_x("name").innerHTML="name:"+newFeature.
document.getElementByIdx_x_x_x("desc").innerHTML="desc:"+newFeature.
function updateData(){
YARINDB.transaction(
function (transaction) {
var data = ['fengsheng yang','I am fengsheng'];
transaction.executeSql("UPDATE yarin SET name=?, desc=? WHERE id = 1", [data[0], data[1]]);
selectAll();
function ddeleteTables(){
YARINDB.transaction(
function (transaction) {
transaction.executeSql("DROP TABLE", [], nullDataHandler, errorHandler);
console.log("Table 'page_settings' has been dropped.");
注意onLoad中的初始化工作
function initLocalStorage(){
if (window.localStorage) {
textarea.addEventListener("keyup", function() {
window.localStorage["value"] = this.
window.localStorage["time"] = new Date().getTime();
}, false);
alert("LocalStorage are not supported in this browser.");
window.onload = function() {
initDatabase();
initLocalStorage();
HTML5地理位置服务在Android中的应用
Android中Java代码
//启用地理定位
webSettings.setGeolocationEnabled(true);
//设置定位的数据库路径
webSettings.setGeolocationDatabasePath(dir);
//配置权限(同样在WebChromeClient中实现)
publicvoid onGeolocationPermissionsShowPrompt(String origin,
GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
super.onGeolocationPermissionsShowPrompt(origin, callback);
在Manifest中添加权限 Xml代码
&uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/&
&uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION"/&
HTML5中 通过navigator.geolocation对象获取地理位置信息 常用的navigator.geolocation对象有以下三种方法: Js代码
//获取当前地理位置
navigator.geolocation.getCurrentPosition(success_callback_function, error_callback_function, position_options)
//持续获取地理位置
navigator.geolocation.watchPosition(success_callback_function, error_callback_function, position_options)
//清除持续获取地理位置事件
navigator.geolocation.clearWatch(watch_position_id)
其中success_callback_function为成功之后处理的函数,error_callback_function为失败之后返回的处理函数,参数position_options是配置项 在JS中的代码Js代码
function get_location() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(show_map,handle_error,{enableHighAccuracy:false,maximumAge:1000,timeout:15000});
alert("Your browser does not support HTML5 geoLocation");
function show_map(position) {
var latitude = position.coords.
var longitude = position.coords.
var city = position.coords.
//telnet localhost 5554
//geo fix -82..054553
//geo fix -121.19 4392
//geo nmea $GPGGA,,,N,,E,0,00,,-19.6,M,4.1,M,,0000*5B
document.getElementByIdx_x_x_x("Latitude").innerHTML="latitude:"+
document.getElementByIdx_x_x_x("Longitude").innerHTML="longitude:"+
document.getElementByIdx_x_x_x("City").innerHTML="city:"+
function handle_error(err) {
switch (err.code) {
alert("permission denied");
alert("the network is down or the position satellites can't be contacted");
alert("time out");
alert("unknown error");
其中position对象包含很多数据 error代码及选项 可以查看文档
构建HTML5离线应用
需要提供一个cache manifest文件,理出所有需要在离线状态下使用的资源
例如Manifest代码
CACHE MANIFEST
images/sound-icon.png
images/background.png
clock.html
style/default.css
/files/projects /projects
在html标签中声明 &html manifest="clock.manifest"& HTML5离线应用更新缓存机制 分为手动更新和自动更新2种 自动更新: 在cache manifest文件本身发生变化时更新缓存 资源文件发生变化不会触发更新 手动更新: 使用window.applicationCache
if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
window.applicationCache.update();
在线状态检测 HTML5 提供了两种检测是否在线的方式:navigator.online(true/false) 和 online/offline事件。在Android中构建离线应用Java代码
//开启应用程序缓存
webSettingssetAppCacheEnabled(true);
String dir = this.getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();
//设置应用缓存的路径
webSettings.setAppCachePath(dir);
//设置缓存的模式
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
//设置应用缓存的最大尺寸
webSettings.setAppCacheMaxSize();
//扩充缓存的容量
publicvoid onReachedMaxAppCacheSize(long spaceNeeded,
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(spaceNeeded * 2);
Copyright (C) , All Rights Reserved.
版权所有 闽ICP备号
processed in 0.041 (s). 13 q(s)android 使用html5作布局文件: webview跟javascript交互 - 为程序员服务
android 使用html5作布局文件: webview跟javascript交互
android 使用html5作布局文件
Android中webview跟JAVASCRIPT中的交互
android软件开发之webView.addJavascriptInterface循环渐进【一】:
android软件开发之webView.addJavascriptInterface循环渐进【二】:
在android开发中,通常使用xml格式来描述布局文件。就目前而言,熟悉android布局及美化的人员少之又少,出现了严重的断层。大部分企业,其实还是程序员自己动手布局。这样既浪费时间和精力,也未必能达到理想的效果。但是,在企业级的android开发中,使用html页面进行布局,也有很多的优势(例如:简单,大部分开发人员及美工都熟悉,方便统一进行更新,管理)。据笔者了解,已经有不少的公司在使用这种方式进行布局开发。这也可能是一种趋势。
下面,我将给出一个实例代码,供大家学习使用html页面给android应用布局。
package com.dazhuo.
import java.util.L
import org.json.JSONA
import org.json.JSONO
import com.dazhuo.domain.P
import com.dazhuo.service.PersonS
import android.app.A
import android.content.I
import android.net.U
import android.os.B
import android.util.L
import android.webkit.WebV
public class MainActivity extends Activity {
private PersonS
private WebV
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
service =new PersonService();
webview = (WebView) this.findViewById(R.id.webView);//android内置浏览器对象
webview.getSettings().setJavaScriptEnabled(true);//启用javascript支持
//添加一个js交互接口,方便html布局文件中的javascript代码能与后台java代码直接交互访问
webview.addJavascriptInterface(new PersonPlugin() , "Person");//new类名,交互访问时使用的别名
// &body onload="javascript:Person.getPersonList()"&
webview.loadUrl("file:///android_asset/index.html");//加载本地的html布局文件
//其实可以把这个html布局文件放在公网中,这样方便随时更新维护
例如 webview.loadUrl("/index.html");
//定义一个内部类,从java后台(可能是从网络,文件或者sqllite数据库) 获取List集合数据,并转换成json字符串,调用前台js代码
private final class PersonPlugin{
public void getPersonList(){
List&Person& list = service.getPersonList();//获得List数据集合
//将List泛型集合的数据转换为JSON数据格式
JSONArray arr =new JSONArray();
for(Person person :list)
JSONObject json =new JSONObject();
json.put("id", person.getId());
json.put("name", person.getName());
json.put("mobile",person.getMobile());
arr.put(json);
String JSONStr =arr.toString();//转换成json字符串
webview.loadUrl("javascript:show('"+ JSONStr +"')");//执行html布局文件中的javascript函数代码--
Log.i("MainActivity", JSONStr);
} catch (Exception e) {
// TODO: handle exception
//打电话的方法
public void call(String mobile){
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ mobile));
startActivity(intent);
package com.dazhuo.
public class Person {
public Integer getId() {
public Person(Integer id, String name, String mobile) {
this.name =
this.mobile =
public void setId(Integer id) {
public String getName() {
public void setName(String name) {
this.name =
public String getMobile() {
public void setMobile(String mobile) {
this.mobile =
package com.dazhuo.
import java.util.ArrayL
import java.util.L
import com.dazhuo.domain.P
public class PersonService {
public List&Person& getPersonList()
List&Person& list =new ArrayList&Person&();
list.add(new Person(32, "aa", ""));
list.add(new Person(32, "bb", ""));
list.add(new Person(32, "cc", ""));
list.add(new Person(32, "dd", ""));
list.add(new Person(32, "ee", ""));
&!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&
&meta http-equiv="Content-Type" content="text/ charset=UTF-8"&
&title&Insert title here&/title&
&script type="text/javascript"&
function show(jsondata){
var jsonobjs = eval(jsondata);
var table = document.getElementById("personTable");
for(var y=0; y&jsonobjs. y++){
var tr = table.insertRow(table.rows.length); //添加一行
//添加三列
var td1 = tr.insertCell(0);
var td2 = tr.insertCell(1);
td2.align = "center";
var td3 = tr.insertCell(2);
td3.align = "center";
//设置列内容和属性
td1.innerHTML = jsonobjs[y].
td2.innerHTML = jsonobjs[y].
td3.innerHTML = "&a href='javascript:Person.call(\""+ jsonobjs[y].mobile+ "\")'&"+ jsonobjs[y].mobile+ "&/a&";
&!-- js代码通过webView调用其插件中的java代码 --&
&body onload="javascript:Person.getPersonList()"&
&table border="0" width="100%" id="personTable" cellspacing="0"&
&td width="20%"&编号&/td&&td width="40%" align="center"&姓名&/td&&td align="center"&电话&/td&
&a href="javascript:window.location.reload()"&刷新&/a&
转自:http://blog.csdn.net/dinglang_2009/article/details/6862627
IT技术文章geek资讯
原文地址:, 感谢原作者分享。
您可能感兴趣的代码}

我要回帖

更多关于 android x5 webview 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信