**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)
剩余的類型就不一一的贅述了。可以參考下表。

