Android JNI

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 },
};

![Screenshot_from_2013-01-28_14_27_12.png]({{ site.url }}/images/Screenshot_from_2013-01-28_14_27_12.png)

![Screenshot_from_2013-01-28_14_46_52.png]({{ site.url }}/images/Screenshot_from_2013-01-28_14_46_52.png)

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