Cordovawebview sendjavascript已弃用

时间:2015-04-30 14:24:12

标签: 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

请帮帮我?

1 个答案:

答案 0 :(得分:0)

这应该适合你: gWebView.loadUrl("javascript:myJavaScriptFuntion();");