So, how can i send strings from JS to JAVA and JAVA to C++ Libraries. The C++ libraries too return the strings to JS to answer the user ?
Because the files do not work.
To send the strings from JS :
loadfileae.myLoad("string1", "string2", "string3", function(msg){
alert(msg);
},function(err){
alert(err);
});
Plugin JS :
module.exports = {
myLoad: function (setData1,setData2,setData3, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "LoadFileAe", "myLoad", [setData1, setData2, setData3]);
}
};
JAVA 1 :
package com.ae.plugin;
import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class LoadFileAe extends CordovaPlugin {
protected static final String TAG = "LoadFile Plugin";
protected CallbackContext context;
@OverRide
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
context = callbackContext;
boolean result = true;
try {
if (action.equals("myLoad")) {
String setData1 = data.getString(0);
String setData2 = data.getString(1);
String setData3 = data.getString(2);
String jniOutput = LoadFileAeJni.stringFromJNI(setData1, setData2, setData3);
String output = jniOutput;
callbackContext.success(output);
}else{
handleError("Invalid loader file !");
result = false;
}
} catch (Exception e) {
handleException(e);
result = false;
}
return result;
}
private void handleError(String errorMsg) {
try {
Log.e(TAG, errorMsg);
context.error(errorMsg);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
private void handleException(Exception exception) {
handleError(exception.toString());
}
}
JAVA 2 :
package com.ae.plugin;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class LoadFileAeJni {
public static native String stringFromJNI(String setData1, String setData2, String setData3);
static {
System.loadLibrary("loadfileae-jni");
}
}
C++ :
#include <string.h>
#include <jni.h>
using namespace std;
JNIEXPORT jstring JNICALL Java_com_ae_plugin_LoadFileAeJni_stringFromJNI
(JNIEnv *env,jobject thisObj, jstring getData1, jstring getData2, jstring getData3){
const char *fichier = env->GetStringUTFChars(getData1, NULL);
const char *uuid = env->GetStringUTFChars(getData2, NULL);
const string *extention = env->GetStringUTFChars(getData3, NULL);
if (fichier == NULL){
fichier="Aucun fichier detecté !";
}
if (uuid == NULL){
uuid="Aucune clé detecté !";
}
if (extention == NULL){
extention="Aucune extention detecté !";
}
env->ReleaseStringUTFChars(getData1, fichier);
env->ReleaseStringUTFChars(getData2, uuid);
env->ReleaseStringUTFChars(getData3, extention);
char resultat[999];
cout << "K7Player C++ Response : " << fichier << "Uuid : " << uuid << "Extention : " << extention << endl;
cin >> resultat;
return env->NewStringUTF(resultat.c_str());
}