Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发现问题 #2

Closed
brucewuu520 opened this issue Nov 6, 2014 · 12 comments
Closed

发现问题 #2

brucewuu520 opened this issue Nov 6, 2014 · 12 comments

Comments

@brucewuu520
Copy link

关于网页调用玩Java后回调js的问题,例如弹出个dialog点击确定后后回调js,但却不成功

@pedant
Copy link
Owner

pedant commented Nov 6, 2014

能不能给出你具体的测试代码, 关于回调可以再详看下ReadMe中“关于异步回调”这条 ,如果使用的是同一个JsCallback,需要在第一次apply前setPermanent(true)。

@brucewuu520
Copy link
Author

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();
}

网页调用这个方法,文档都仔细读了,就是和例子不一样的是我没有延迟执行回调,我想这应该不会有问题的吧

@pedant
Copy link
Owner

pedant commented Nov 6, 2014

我按照你的Java代码测试是可以的,我的网页端的js调用代码如下:

HostApp.iknowAlertDialog('My Title', 'This is Content', function (msg) {console.log(msg);});

成功在控制台输入了success。 你的网页端的js调用代码是怎样的?
另外你这种callback不需要复用的,是不需加setPermanent(true)

@brucewuu520
Copy link
Author

FKAPP.iknowAlertDialog('标题', '收到知道了', function (msg) {
alert(msg||445);
});
这样的啊

@pedant
Copy link
Owner

pedant commented Nov 6, 2014

alert里面是计算结果是一个整型值,你的java注入类里面实现了类似 public static void alert (WebView webView, int msg) 这样的方法吗? 建议你把alert换成console 调试下,另外其他注入方法调用正常吗?

@brucewuu520
Copy link
Author

试了很多种,也这么写过:
FKAPP.iknowAlertDialog('标题', '收到知道了', function (msg) {
document.write('jkie');

});
网页上也没写出“jkie”,证明是没有回调成功吧?是不是webview的配置什么的有干扰?

@brucewuu520
Copy link
Author

在studio log 里打印出了这个E/Web Console﹕ Uncaught ReferenceError: HostApp is not defined at null:1
HostApp不是调用名吗,我已改为FKAPP了啊,这是怎么回事呢?

@brucewuu520
Copy link
Author

打开网页时的后台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

@brucewuu520
Copy link
Author

点击调用后的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

@pedant
Copy link
Owner

pedant commented Nov 6, 2014

看日志,明白了, 是library代码库的自定义命名问题。你今天可以先把FKAPP换回HostApp开测试,明天提交个commit修复。感谢提前发现😊

@pedant
Copy link
Owner

pedant commented Nov 7, 2014

@brucewuu520 昨天的问题已修复,望知悉,004006e

@brucewuu520
Copy link
Author

@pedant ok thanks

@pedant pedant closed this as completed Nov 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants