Android JNI
· 1 min read
JNINativeMethod struct
typedef struct {
const char* name;
const char* signature;
void* fnPtr;
} JNINativeMethod;
name: java function name signature: use a string description function’s parameter and return type fnPtr: a function pointer point to native function, it’s first add (void *)
How to write the second paramter?
static JNINativeMethod methods[] = {
{ "\_setDataSource", "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)V", (void _)android_media_MediaPlayer_setDataSourceAndHeaders },
{ "setDataSource", "(Ljava/io/FileDescriptor;)V", (void _)android_media_MediaPlayer_setDataSourceFD },
};
- () express jni function paramter and back express return value(V: void Function())
- Primitive types

- Reference types

object type: To the beginning of the “L”, “;” at the end, in the middle is “/” separated array type: To the beginning of the “[”