ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
**Android NDK开发学习(五):JNI数据类型** 调用一个Java native方法的时候,方法中的参数需要传给C/C++本地函数中。 首先可以看之前的demo,stringFromJNI方法中传入一个String类型参数。 ~~~ public class GetString { public native String stringFromJNI(String string); } ~~~ 接下来是com_example_jnitest_GetString.h文件中的接收 ~~~ #include <jni.h> /* Header for class com_example_jnitest_GetString */ #ifndef _Included_com_example_jnitest_GetString #define _Included_com_example_jnitest_GetString #ifdef __cplusplus extern "C" { #endif /* * Class: com_example_jnitest_GetString * Method: stringFromJNI * Signature: (Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_example_jnitest_GetString_stringFromJNI (JNIEnv *, jobject, jstring); #ifdef __cplusplus } #endif #endif ~~~ 从头文件函数的原型可以得知,stringFromJNI方法中形参的数据类型自动转换成了JNI中相应的数据类型(String ····> jstring) 剩余的类型就不一一的赘述了。可以参考下表。 ![](https://box.kancloud.cn/2016-04-26_571f24eb4cc40.jpg) ![](https://box.kancloud.cn/2016-04-26_571f24eb645d6.jpg)