[英]One of three functions not being called using QAndroidJniObject
Here is the code that calls three functions from my custom java class: 这是从我的自定义java类调用三个函数的代码:
QAndroidJniObject datafile = QAndroidJniObject::fromString(path);
QAndroidJniObject password = QAndroidJniObject::fromString("asimpletest");
QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
"AESCryptInit",
"(Ljava/lang/String;Ljava/lang/String;)V;",
password.object<jstring>(),
datafile.object<jstring>());
QAndroidJniObject decrypted_data = QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
"decrypt",
"()Ljava/lang/String;");
QAndroidJniObject fname = QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
"getFilename",
"()Ljava/lang/String;");
QAndroidJniObject status = QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
"getStatus",
"()Ljava/lang/String;");
Here is the java code for three of these functions: 这是其中三个函数的Java代码:
The non working one: 不工作的一个:
public static void AESCryptInit (String passwd, String datafile){
// Initializing variables.
rawdata = null;
status = "";
fileName = datafile;
Log.i("[QCOLOCRYPT]","The filename is " + datafile);
// Transforming the passwd to 16 bytes.
try {
MessageDigest digester = MessageDigest.getInstance("MD5");
InputStream in = new ByteArrayInputStream(Charset.forName(encoding).encode(passwd).array());
byte[] buffer = new byte[NCHARS];
int byteCount;
while ((byteCount = in.read(buffer)) > 0) {
digester.update(buffer, 0, byteCount);
}
keyBytes = digester.digest();
}
catch(Exception e){
status = "Error in key generation: " + e.toString();
}
// Initilizing the crypto engine
try {
cipher = Cipher.getInstance(algorithm);
}
catch(Exception e){
status = "Error in intialization: " + e.toString();
}
secretKeySpec = new SecretKeySpec(keyBytes, "AES");
ivParameterSpec = new IvParameterSpec(keyBytes);
}
And two that work 还有两个有效
// Getting status
public static String getStatus(){return status;}
public static String getFilename() {
Log.i("[QCOLOCRYPT]","Getting the file name");
return "The Filename is: " + fileName;
}
The non-working function is not being called because its debug message is NOT being printed, while I get the log message AND the return values of the other two. 由于正在打印日志消息以及其他两个函数的返回值,因此未打印其调试消息,因此未调用非工作函数。 Logcat does not seem to show any errors, so I'm at a loss.
Logcat似乎没有显示任何错误,所以我很茫然。 Am I calling it wrong?
我说错了吗?
Ok, so this isn't exactly an answer. 好的,所以这不是一个答案。 It's more of a workaround, I got the function to work, but the only way I could do it is by returning a String.
这更多是一种解决方法,我可以使用该函数,但是唯一的方法是返回String。 I've tried with an Integer using (Arguments)I;
我已经尝试过使用(Arguments)I; as the signature but I had the same problem.
作为签名,但我遇到了同样的问题。 I modified the Java function to return a status string, changed the signature to reflect that, and everything worked perfectly.
我修改了Java函数以返回状态字符串,更改了签名以反映这一点,并且一切正常。 Though its weird.
虽然很奇怪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.