GithubHelp home page GithubHelp logo

Comments (12)

pedant avatar pedant commented on July 2, 2024

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

from safe-java-js-webview-bridge.

brucewuu520 avatar brucewuu520 commented on July 2, 2024
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.

pedant avatar pedant commented on July 2, 2024

我按照你的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.

brucewuu520 avatar brucewuu520 commented on July 2, 2024

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

from safe-java-js-webview-bridge.

pedant avatar pedant commented on July 2, 2024

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

from safe-java-js-webview-bridge.

brucewuu520 avatar brucewuu520 commented on July 2, 2024

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

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

from safe-java-js-webview-bridge.

brucewuu520 avatar brucewuu520 commented on July 2, 2024

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

from safe-java-js-webview-bridge.

brucewuu520 avatar brucewuu520 commented on July 2, 2024

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

brucewuu520 avatar brucewuu520 commented on July 2, 2024

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

pedant avatar pedant commented on July 2, 2024

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

from safe-java-js-webview-bridge.

pedant avatar pedant commented on July 2, 2024

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

from safe-java-js-webview-bridge.

brucewuu520 avatar brucewuu520 commented on July 2, 2024

@pedant ok thanks

from safe-java-js-webview-bridge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.