java - Cordovawebview sendjavascript 已弃用

标签 java android cordova cordova-plugins

Cordova Web View sendjavascript 已弃用,它对我不起作用。 我的 Java 代码是:

public static void sendJavascript(JSONObject _json) {
    String _d = "javascript:" + gECB + "(" + _json.toString() + ")";
    Log.v(TAG, "sendJavascript: " + _d);
    Log.i(TAG,_d);
    if (gECB != null && gWebView != null) {
        gWebView.sendJavascript(_d);//deprecated method
    }
}

我的java脚本代码:

document.addEventListener("deviceready", function(){

       window.plugins.pushNotification.register(successHandler, errorHandler, {
            ecb      : 'onNotificationGCM',
            senderID : 'xxxxxxxxxxxxx'
        });

    // Method to handle device registration for Android.
        var onNotificationGCM = function(e) {
            if('registered' === e.event) {
                // Successfully registered device.
                alert(e.regid);
            }
            else if('error' === e.event) {
                // Failed to register device.
                alert(e.msg);
            }
            else if('message' === e.event) {
                //mesage recived 
                alert(e.payload.message);
            }

        };


        // result contains any message sent from the plugin call
        function successHandler (result) {
            alert('gcm result = ' + result);
        }

        // result contains any error description text returned from the plugin call
        function errorHandler (error) {
            alert('error = ' + error);
        }   
    });

已弃用的详细信息:https://apache.googlesource.com/cordova-android/+/3.6.1/framework/src/org/apache/cordova/CordovaWebView.java

请帮帮我好吗?

最佳答案

这应该对你有用: gWebView.loadUrl("javascript:myJavaScriptFuntion();");

关于java - Cordovawebview sendjavascript 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29970350/

相关文章:

java - 将字符串中的所有其他单词大写

java - 性能:单变量赋值与对象图导航 (Java)

java - 以相对布局自动组织 View |安卓工作室

javascript - 如何在html5、Android、Phonegap中添加Scroller

ios - Ionic - 缺少推送通知权利

angular - 电容器和 ionic native 状态栏

java - 这个 IntStream 分区实现真的不是线程安全的吗?

java - TomCat 正在占用 100% 的 CPU。有没有我可以输入的命令来阻止它这样做

java - 如何从库中检测应用程序已暂停(未终止)和已恢复(未创建)

带有 ButtonBar 的 RelativeLayout 中的 Android Scrollview