在 C++ 上下文中,当使用 QAndroidJniObject JNI 从 java 上下文调用函数时,无法检索 jlong 的值。仅检索 jstring 值。如何提取jlong?如何才能做到这一点?如果在 Qt 中可能的话,也许我需要在 JNI extern C... 上传递而不是 QAndroidJniObject ?
//----------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
}