Comments (12)
能不能给出你具体的测试代码, 关于回调可以再详看下ReadMe中“关于异步回调”这条 ,如果使用的是同一个JsCallback,需要在第一次apply前setPermanent(true)。
from safe-java-js-webview-bridge.
public static void iknowAlertDialog(WebView view, String title, String content, final JsCallback callback) {
callback.setPermanent(true);
new AlertDialog.Builder(view.getContext())
.setTitle(title).setMessage(content)
.setPositiveButton("我知道了", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
callback.apply("success");
}
}).show();
}
网页调用这个方法,文档都仔细读了,就是和例子不一样的是我没有延迟执行回调,我想这应该不会有问题的吧
from safe-java-js-webview-bridge.
我按照你的Java代码测试是可以的,我的网页端的js调用代码如下:
HostApp.iknowAlertDialog('My Title', 'This is Content', function (msg) {console.log(msg);});
成功在控制台输入了success。 你的网页端的js调用代码是怎样的?
另外你这种callback不需要复用的,是不需加setPermanent(true)。
from safe-java-js-webview-bridge.
FKAPP.iknowAlertDialog('标题', '收到知道了', function (msg) {
alert(msg||445);
});
这样的啊
from safe-java-js-webview-bridge.
alert里面是计算结果是一个整型值,你的java注入类里面实现了类似 public static void alert (WebView webView, int msg) 这样的方法吗? 建议你把alert换成console 调试下,另外其他注入方法调用正常吗?
from safe-java-js-webview-bridge.
试了很多种,也这么写过:
FKAPP.iknowAlertDialog('标题', '收到知道了', function (msg) {
document.write('jkie');
});
网页上也没写出“jkie”,证明是没有回调成功吧?是不是webview的配置什么的有干扰?
from safe-java-js-webview-bridge.
在studio log 里打印出了这个E/Web Console﹕ Uncaught ReferenceError: HostApp is not defined at null:1
HostApp不是调用名吗,我已改为FKAPP了啊,这是怎么回事呢?
from safe-java-js-webview-bridge.
打开网页时的后台log:
11-06 20:02:49.648 23648-23648/com.jidian.android.edo D/InjectedChromeClient﹕ inject js interface completely on progress 100
11-06 20:02:49.668 23648-23648/com.jidian.android.edo I/Web Console﹕ HostApp initialization begin at null:1
11-06 20:02:49.668 23648-23648/com.jidian.android.edo I/Web Console﹕ HostApp initialization end at null:1
from safe-java-js-webview-bridge.
点击调用后的log:
11-06 20:03:49.528 23648-24115/com.jidian.android.edo E/webcoreglue﹕ Should not happen: no rect-based-test nodes found
11-06 20:03:49.918 23648-23648/com.jidian.android.edo D/JsCallJava﹕ HostApp call json: {"method":"iknowAlertDialog","types":["string","string","function"],"args":["标题","收到点",0]} result:{"code": 200, "result": null}
11-06 20:03:51.058 23648-23648/com.jidian.android.edo D/JsCallBack﹕ javascript:HostApp.callback(0, 0 ,"success");
11-06 20:03:51.078 23648-23648/com.jidian.android.edo E/Web Console﹕ Uncaught ReferenceError: HostApp is not defined at null:1
from safe-java-js-webview-bridge.
看日志,明白了, 是library代码库的自定义命名问题。你今天可以先把FKAPP换回HostApp开测试,明天提交个commit修复。感谢提前发现😊
from safe-java-js-webview-bridge.
@brucewuu520 昨天的问题已修复,望知悉,004006e 。
from safe-java-js-webview-bridge.
@pedant ok thanks
from safe-java-js-webview-bridge.
Related Issues (20)
- 这个在iOS适用么? HOT 1
- JsCallback.apply(String对象)出错
- 我把你的JsCallJava的代码改了一下,用起来会更加灵活:(你可以参考一下)
- 我把你的JsCallJava.java修改了一下,这样使用起来更加灵活:(你可以参考一下) HOT 1
- 参数长度有限制,太长会报错
- 文章地址域名过期了! HOT 1
- history.back()失效 HOT 2
- import error HOT 1
- 动态注入的js内容怎么查看? HOT 1
- Java代码中要打开Activity,怎么实现 HOT 1
- js异步调用native代码时,如果回调的参数长度大于4000,则无法回调。
- 这个能否解决4.2以下,js注入漏洞问题吗? HOT 2
- WebView默认接口searchBoxJavaBridge_依然存在js注入漏洞
- 注册给InjectedChromeClient的JAVA类接口不支持注册多个类吗
- Android如何调用js呢? HOT 1
- 请教一个问题 HOT 1
- 请教个问题 HOT 1
- JS怎么传方法给JAVA进行执行 HOT 1
- 很多机型上注入不成功 HOT 10
- 请问pendant如何传递JSONArray呢 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from safe-java-js-webview-bridge.