问题描述
我想创造一个我想从我的Java code将数据传输回JS一个销售人员插件(这基本上是一个后台进程)
但是,它总是给我错误行this.sendJavascript(函数名)
I am trying to create a salesforce plugin in which i want to push data back to JS from my java code (which is basically a background process)But its always giving me error for line this.sendJavascript(function name)
以下是插件code -
following is plugin code -
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);
}
}
我已标记的误差线是在末尾。请帮我解决这个
I have marked the error line which is at the end. Please help me resolve this
在此先感谢,
考希克
Thanks in Advance,Kaushik
推荐答案
sendJavascript()
在两个DroidGap.java和CordovaWebView.java功能,但价值这个
在当前文件是回声的实例。行 this.sendJavascript()
失败,因为期待称为是回声的成员,或从继承的一个类的公共/受保护的成员函数,在此案例CordovaPlugin。
sendJavascript()
is a function in both DroidGap.java and CordovaWebView.java, but the value of this
in your current file is your instance of Echo. The line this.sendJavascript()
fails because is expecting the function called to be a member of Echo or a public/protected member of one of the classes it inherited from, in this case CordovaPlugin.
有在CordovaPlugin.java web视图
公共变量,命名它是为您的项目CordovaWebView。如果您从 this.sendJavascript改变你的那一行(JS)
到 webView.sendJavascript(JS)
,它应该修复您的错误。
There is a public variable in CordovaPlugin.java, named webView
which is the CordovaWebView for your project. If you change your offending line from this.sendJavascript(js)
to webView.sendJavascript(js)
, it should fix your error.
这篇关于sendJavascript功能不是在科尔多瓦插件销售人员定义的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!