[Android]Webview中JS接口调用Java-版本问题

问题:

The javascript to java bridge on 2.3 Gingerbread is causing crashes.  This is 100% reproducible using the WebViewDemo application from here: http://code.google.com/p/apps-for-android/source/browse/#svn/trunk/Samples/WebViewDemo.
Note: The project file for that app is a little messed up, however, if you recreate the project, keeping the code the same, you can reproduce the error. The sample is old, but the code should still run as none of these interfaces have been deprecated.

It is also easily reproducible by creating a simple application that creates a webview, enables javascript, adds a JS interface, then loads a script into the webview. The code for this even simpler app is attached as well as WebViewTest and a secondary Test class as the "bridge".

The demos work as expected when using 2.2

This is a serious issue as it will cause crashes for any app using the webview to do any serious work. Thanks in advance for taking a look at this.

Attached is the output from logcat as well as the output from adb bugreport.





log.txt
8.3 KB   View   Download





bug.txt
1.1 MB   View   Download





WebViewTest.java
764 bytes
  View   Download





Test.java
149 bytes   View   Download

解决方案:

安卓2.3中会有问题,换个target版本启动即可解决。

参考:

https://code.google.com/p/android/issues/detail?id=12987

[Android]Webview中JS接口调用Java-版本问题

时间: 2024-08-10 17:18:00

[Android]Webview中JS接口调用Java-版本问题的相关文章

Webview 中 Javascript 无法调用 Java 对象

[问题产生] Webview 通过 addjavascriptInterface 传递对象给前端,一切正常.但是 Android官方已提醒此功能是有安全风险,改用 safe-java-js-webview-bridge 做java和js交互. 官方的用法正常: <ul class="entry"> <li onclick="HostApp.alert('HostApp.alert');">HostApp.alert</li> &l

Android WebView使用之JavaScript调用Java代码注意事项

1.被调用的函数上方要添加注释(@android.webkit.JavascriptInterface);否则JavaScript无法找到该方法.

WebView中JS调用Android Method 遇到的坑整理

WebView是android中常用的一个组件,其作用是展示网页,并让网页和android app进行一些业务逻辑上的交互. 其坑无数,相信用过的都知道,一个一个来解决吧. 1.怎么互调: <!DOCTYPE> <html> <head> <meta charset="UTF-8"> <script type="text/javascript"> function android(bl){ if(bl){

WebView中Js与Android本地函数的相互调用

介绍 随着Html5的普及,html在表现力上不一定比原生应用差,并且有很强的扩展兼容性,所以越来越多的应用是采用Html与Android原生混合开发模式实现. 既然要实现混合开发,那么Js与Android原生函数的相互调用就必不可少了.这里写了一个demo,实现点击html中的图片进行本地展示. 原理 1.Android调用js很简单,直接webView.loadUrl("javascript:JS中的方法名称()");即可. 2.js调用Android方法,需要使用WebView.

webview中js调用Android中的方法

package com.example.helloworld; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.webkit.WebView; public class MainActivity extends Activity { private WebView webView = null

如何在android平台上使用js直接调用Java方法[转]

转载自:http://www.cocos.com/docs/html5/v3/reflection/zh.html #如何在android平台上使用js直接调用Java方法 在cocos2d-js 3.0beta中加入了一个新特性,在android平台上我们可以通过反射直接在js中调用java的静态方法.它的使用方法很简单: var o = jsb.reflection.callStaticMethod(className, methodName, methodSignature, parame

[转载]android常用的API接口调用

原文地址:android常用的API接口调用作者:宋耀 显示网页:         Uri uri = Uri.parse("http://www.google.com"); Intent it = new Intent(Intent.ACTION_VIEW,uri); startActivity(it);显示地图: Uri uri = Uri.parse("geo:38.899533,-77.036476"); //Uri uri = Uri.parse(&quo

Android:WebView中对图片注册上下文菜单

前言 今天一朋友问我一个问题,就是如何在WebView控件中的图片增加上下文菜单,以便增加保存图片等功能.今天就给他简单做了一个演示Demo,现写下来,给有相同问题的朋友提供些许思路吧. 概要实现 其实这个功能很简单,没有太复杂的东西,就是对WebView的控件的使用,一是给WebView注册了上下文菜单事件,二是在响应事件中去判断事件源的类型,如果是图片类型,则把url取出来 注册上下文菜单事件 这个就比较简单了通过下面的代码即可完成. WebView vw = (WebView) findV

android webview中调用了js的时候混淆注意事项

今天有一个bug,就是webview跟js交互的方法怎么也调不起来,debug包问题,release包就出错,想想是打包时混淆的问题,打了一个不混淆的包,果不其然,就是混淆的问题. 然后就找解决方案,在proguard-project文件中有这么一句 <span style="font-family:KaiTi_GB2312;font-size:14px;"># If your project uses WebView with JS, uncomment the foll