thread.start();
//加载所有的数据 备注:在android 17版本之后必须通过 @JavascriptInterface 注解实现,
//否则会出现"Uncaught TypeError: Object [object Object] has no method 'userList'",
//source: file:///android_asset/user.html (31)
//这个方法是在网页中调用的onload="javascript:csdn.userList()"
@JavascriptInterface
public void userList() {
handler.post(new Runnable() {
@Override
public void run() {
try {
//获得List数据集合
List
//json格式数据转换
JSONArray jsonArray =new JSONArray();
for(FootMarkContent person :list)
{
JSONObject json =new JSONObject();
json.put("id", person.getId());
json.put("name", person.getName());
json.put("mobile",person.getMobile());
jsonArray.put(json);
}
// 把json数组转换成字符串
String jsonstr = jsonArray.toString();
Log.i("MainActivity", "返回给前端数据:"+jsonstr);
// 调用网页中的javascript中的show函数
wv_footcontent.loadUrl("javascript:show('" + jsonstr + "')");
Log.i("MainActivity", "前端拿到的数据:"+jsonstr);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
// 打电话 备注:在android17版本之后必须通过 @JavascriptInterface 注解实现,否则会出现bug(详见异常)
//这个方法是在网页中调用的:"+ jsonobjs[y].name + "
@JavascriptInterface
public void call(final String phone) {
//处理的操作要在hanlder中处理
handler.post(new Runnable() {
@Override
public void run() {
//这里要实现打电话的操作,必须添加打电话的权限
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone)));
}
});
}