Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Cordova插件salesforce中未定义sendJavascript函数错误_Android_Cordova_Salesforce_Phonegap Plugins - Fatal编程技术网

Android Cordova插件salesforce中未定义sendJavascript函数错误

Android Cordova插件salesforce中未定义sendJavascript函数错误,android,cordova,salesforce,phonegap-plugins,Android,Cordova,Salesforce,Phonegap Plugins,我正在尝试创建一个salesforce插件,在这个插件中,我希望将数据从java代码推回到JS(这基本上是一个后台过程) 但是这行代码总是给我错误。sendJavascript(函数名) 以下是插件代码- package com.salesforce.androidsdk.phonegap; import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CordovaPlugin; import org.

我正在尝试创建一个salesforce插件,在这个插件中,我希望将数据从java代码推回到JS(这基本上是一个后台过程) 但是这行代码总是给我错误。sendJavascript(函数名)

以下是插件代码-

package com.salesforce.androidsdk.phonegap;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
/**
 * This class echoes a string called from JavaScript.
 */
public class Echo extends CordovaPlugin {
    private static final String TAG = "CordovaPlugin";

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        Log.i(TAG,"inside execute method--->>>" + action + args + callbackContext);
        if (action.trim().equalsIgnoreCase("echo")) {
            Log.i(TAG,"args.getString(0)--->>>" + args.getString(0));
            String message = args.getString(0); 
            // Initialise the service variables and start it it up
            Context thiscontext = this.cordova.getActivity().getApplicationContext();
            Intent callBackgroundService = new Intent(thiscontext, CallBackgroundService.class);
            callBackgroundService.putExtra("loadinterval", 800); // Set LED flash interval
            thiscontext.startService(callBackgroundService);
            this.echo(message, callbackContext);

            sendValue("Kaushik", "Ray");
            return true;
        }
        return false;
    }

    private void echo(String message, CallbackContext callbackContext) {
        if (message != null && message.length() > 0) { 
            callbackContext.success(message);
        } else {
            callbackContext.error("Expected one non-empty string argument.");
        }
    }

    public void sendValue(String value1, String value2) {
         JSONObject data = new JSONObject();
        try {
            data.put("value1", "Kaushik");
            data.put("value2", "Ray");
        } catch (JSONException e) {
            Log.e("CommTest", e.getMessage());
        }
         String js = String.format(
                "window.plugins.commtest.updateValues('%s');",
                data.toString());
    error line ------->>>  this.sendJavascript(js);

    }
}
我已在末尾标记了错误行。请帮我解决这个问题

提前感谢,, Kaushik

sendJavascript()
是DroidGap.java和CordovaWebView.java中的一个函数,但当前文件中的
this
的值是Echo的实例。行
this.sendJavascript()
失败,因为它希望调用的函数是Echo的成员或它继承自的某个类(在本例中为CordovaPlugin)的公共/受保护成员


CordovaPlugin.java中有一个公共变量,名为
webView
,它是项目的CordovaWebView。如果您将有问题的行从
this.sendJavascript(js)
更改为
webView.sendJavascript(js)
,它将修复您的错误。

事实上,我刚刚解决了这个问题。。!!谢谢你的帮助。。!!我还有一个疑问,我正在调用一个名为CallBackgroundService.java的代码中定义的后台服务类,但我无法将值从android中的服务传递回JS…任何指针都可以…?很高兴听到您已经解决了问题。至于您的另一个问题,在没有看到一些代码的情况下,我不是很确定,但听起来这可能是值得再发布一个问题的地方!