Javascript的接口不工作与Android 4.2接口、工作、Javascript、Android

由网友(ζ 给力ㄨ 侽刄)分享简介:我现在面临的Andr​​oid操作系统果冻豆4.2的一个严重的错误,在这里我的计划,我用JavaScript来让网页的高度,这是完全从Android 2.2的工作到4.1,但是当我试图用同样的code在安卓4.2这样的JavaScript接口不能正常工作。I am facing a serious bug of an...

我现在面临的Andr​​oid操作系统果冻豆4.2的一个严重的错误,在这里我的计划,我用JavaScript来让网页的高度,这是完全从Android 2.2的工作到4.1,但是当我试图用同样的code在安卓4.2这样的JavaScript接口不能正常工作。

I am facing a serious bug of android OS Jelly Bean 4.2, here in my program I am using JavaScript to get the height of webpage and it is perfectly working from android 2.2 to 4.1 but when I tried to use the same code in android 4.2 so the JavaScript interface not working.

我该如何解决这个问题?

How can I fix this issue?

推荐答案

从Android 4.2的文档:

From the Android 4.2 documentation:

注意:如果你已经设置你的targetSdkVersion为17或更高,则必须添加@JavascriptInterface标注任何你想用你的网页code(该方法也必须是公共的)方法。如果你不提供注释,则该方法将在Android 4.2或跑步时,不是被你的网页中较高的。

Caution: If you've set your targetSdkVersion to 17 or higher, you must add the @JavascriptInterface annotation to any method that you want available your web page code (the method must also be public). If you do not provide the annotation, then the method will not accessible by your web page when running on Android 4.2 or higher.

来源:的Andr​​oid的WebView文档

阅读全文

相关推荐

最新文章