我在我的 android Activity 中编写此代码,以向 android ndk 中的 C 发送请求:
Toast.makeText(getApplicationContext(),Calculate("1")+"",Toast.LENGTH_SHORT).show();
public native String Calculate(String j_key_name);
在 C 文件的 ndk 端,我编写了以下代码:
JNIEXPORT jstring JNICALL
Java_org_sample_aguar_NActivity_Calculate(JNIEnv *env, jobject thiz, jstring j_key_name) {
if (j_key_name == "1") {
return (*env)->NewStringUTF(env, " its 1 ");
} else{
return (*env)->NewStringUTF(env, " it's not 1 ");
}
}
我没有任何错误,但这总是运行其他部分,当我发送“1”作为响应时,我得到(它不是 1 )。
最佳答案
I have written simple if-else program in c. I use String.h library in it and working correctly.
#include<string.h>
char j_key_name[] ="1";
int check = strcmp(j_key_name, "1");
if (check == 0) {
printf("if");
} else{
printf("else");
}
Let's try above code. Hopefully solve your issue. Thanks in advance.
关于java - 将值发送到 android ndk 中的 C 并获取示例(if)响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60629315/