0
我想創建一個salesforce插件,我想從我的java代碼(這基本上是一個後臺進程)推回數據到JS 但它總是給我錯誤線this.sendJavascript(功能名)SendJavascript函數沒有定義錯誤科爾多瓦插件salesforce
以下是插件代碼 -
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);
}
}
我已標記誤差線是在末端。請幫我提前解決這個
感謝, 考希克
其實我只是解決了這個問題..!感謝您的幫助.. !!我有另外一個懷疑我打電話給一個後臺服務類的代碼稱爲CallBackgroundService.java,但我無法將值從我的服務在Android傳遞給JS ...任何指針PLZ ...? – RayKaushik 2013-05-06 19:16:54
很高興聽到你已經弄清楚了事情。至於你的其他問題,沒有看到一些代碼,我不太確定,但聽起來這可能是值得發佈另一個問題的東西! – MattDavis 2013-05-06 19:27:04