In the C++ context, it is not possible to retrieve the value of jlong when calling a function from the java context using the QAndroidJniObject JNI. Only the jstring value is retrieved. How to extract jlong? How can this be done? Maybe I need on JNI extern C to pass instead of QAndroidJniObject if it is possible in Qt?
//----------In Java context:
package com.sim.lib.operation.OperationData
public class OperationData {
private final String mID;
private Long mAmount;
public String getID() {
return this.mID;
}
public Long getAmount() {
return this.mAmount;
}
OperationData(){
this.mAmount = 55;
this.mID = "someid111";
}
}
//----------In Java context:
//other package
import com.sim.lib.operation.OperationData
public static native void approvedStatusSendToQt(java.lang.Object statusObj);
OperationData mOperationData = new OperationData();
approvedStatusSendToQt((Object)mOperationData);
//------------------------------------------------In C++ context:
void AndroidClass::registerNatives()
{
JNINativeMethod methods[] {
{"approvedStatusSendToQt", "(Ljava/lang/Object;)V",reinterpret_cast<void *>(onOperationStatusApprovedReceived)}
}
//.....register method
};
static void onOperationStatusApprovedReceived(JNIEnv *env, jobject /*thiz*/,jobject statusObj)
{
QAndroidJniObject callbackObj(statusObj);
qDebug()<<"mId"<<callbackObj.callObjectMethod<jstring>("getID").toString(); //Print "someid111" it's ok
qDebug()<<"mAmount"<< callbackObj.callMethod<jlong>("getAmount", "()J"); //Print exception System.err: java.lang.NoSuchMethodError: no non-static method "Lcom/sim/lib/operation/OperationData;.getAmount()J"
//qDebug()<<"mAmount"<< callbackObj.callMethod<jlong>("getAmount");//the same mistake
}