的WebView的JavaScript Bridge文档 [英] WebView JavaScript Bridge Documentation

查看:146
本文介绍了的WebView的JavaScript Bridge文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有关于JavaScript的网页视图大桥的任何文档?我找的文档,描述了JavascriptInterface中定义的方法的功能和支持的数据类型。

Is there any documentation regarding the WebView JavaScript Bridge? I am looking for documentation that describes the capabilities and supported data types for methods defined within the "JavascriptInterface".

例如,如果我定义了以下内容:

For example if I define the following:

public class JavaScriptInterface {

    public int incrementNumber(int num) {
       return num + 1;

}

如果我呼吁在JavaScript中此方法并在模拟器中运行它,一切似乎都正常工作。如果我在我的NexusOne运行这一点,数参数传递始终为0。

If I call this method from within JavaScript and run it in the emulator, everything seems to work fine. If I run this on my NexusOne, the passed in "num" argument is always "0".

如果我改变上面:

 public class JavaScriptInterface {

    public int incrementNumber(String num) {
       // Leaving out try/catch
       int tempNum = newRadius = Integer.parseInt(num);
       return tempNum + 1;

}

...一切似乎工作。所以我想知道如果JavaScriptInterface方法的参数应该/只能是String类型的?

... everything seems to work. So I am wondering if JavaScriptInterface method arguments should/can only be of type String?

相关资源:
http://developer.android.com/reference/android/webkit/WebView.html
http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String中)
HTTP://$c$c.google.com/apis/maps /articles/android_v3.html

推荐答案

您可以要求在Java端字符串ARGS或确保数字是实际的数字(而不是文本的数字版本 - 看的 about.com - 的JavaScript:字符串到数字)在JavaScript端

You can either require String args on the Java side or ensure that numbers are actual numbers (and not text versions of numbers - see about.com - JavaScript: Strings to Numbers) on the JavaScript side.

这篇关于的WebView的JavaScript Bridge文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆