以下代码是在Fragment中设计的,用于调用JavaScript文件(MyMap)并调用函数(updateJSONandMap)。该函数本身发送一个JSON到一个服务器并有三个参数。它在第一个参数硬编码(“Incident”)时工作,但在创建变量时不起作用。调用javascript函数不接受可变参数
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.loadUrl("file:///android_asset/MyMap.html");
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
webview.loadUrl("javascript:updateJSONandMap('Incident'," + latitude + "," + longitude + ")");
}
});
的JSON的文本的块是一个字符串
Event: {
Action: 'PUT',
Value: {"S": UserEvent}
},
明显创建变量
final String incident = "incident2";
然后
webview.loadUrl("javascript:updateJSONandMap(" + incident + "," + latitude + "," + longitude + ")");
不创建错误,但不会发送JSON服务器
明显incident2是一个变量,“incident2”是一个字符串 – Selvin