android_hardware_Camera。cpp之中定義了一個JNINativeMethod(JAVA本地調用方法)類型的數組gMethods,以下所示:java
static JNINativeMethod camMethods[] = { {"native_setup","(Ljava/lang/Object;)V",(void*)android_hardware_Camera_native_setup }, {"native_release","()V",(void*)android_hardware_Camera_release }, {"setPreviewDisplay","(Landroid/view/Surface;)V",(void *)android_hardware_Camera_setPreviewDisplay }, {"startPreview","()V",(void *)android_hardware_Camera_startPreview }, {"stopPreview", "()V", (void *)android_hardware_Camera_stopPreview }, {"setHasPreviewCallback","(Z)V",(void *)android_hardware_Camera_setHasPreviewCallback }, {"native_autoFocus","()V",(void *)android_hardware_Camera_autoFocus }, {"native_takePicture", "()V", (void *)android_hardware_Camera_takePicture }, {"native_setParameters","(Ljava/lang/String;)V",(void *)android_hardware_Camera_setParameters }, {"native_getParameters", "()Ljava/lang/String;",(void *)android_hardware_Camera_getParameters } };JNINativeMethod的第一個成員是一個字符串,表示了JAVA本地調用方法的名稱,這個名稱是在JAVA程序中調用的名稱;第二個成員也是一個字符串,表示JAVA本地調用方法的參數和返回值;第三個成員是JAVA本地調用方法對應的C語言函數。
register_android_hardware_Camera 函數將gMethods註冊爲的類"android/media/Camera",其主要的實現以下所示。android
int register_android_hardware_Camera(JNIEnv *env) { // Register native functions return AndroidRuntime::registerNativeMethods(env, "android/hardware/Camera", camMethods, NELEM(camMethods)); }"android/hardware/Camera"對應JAVA的類android。hardware。Camera。