[英]Send a value to C in android ndk and get sample (if) response
i write this code in my android Activity to send a request to C in android ndk:我在我的 android Activity 中编写此代码以向 android ndk 中的 C 发送请求:
Toast.makeText(getApplicationContext(),Calculate("1")+"",Toast.LENGTH_SHORT).show();
public native String Calculate(String j_key_name);
and in ndk side in C file i write this code:在 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 ");
}
}
i don't have any error But That's always run else part and when i send "1" in response i get (it's not 1 ).我没有任何错误但这总是运行其他部分,当我发送“1”作为响应时,我得到(它不是 1 )。
I have written simple if-else program in c.我用 c 编写了简单的 if-else 程序。 I use String.h library in it and working correctly.我在其中使用 String.h 库并正常工作。
#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.提前致谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.