Last active
June 10, 2021 03:43
-
-
Save whatisor/e114606079e5c99752ea5678429800b6 to your computer and use it in GitHub Desktop.
How to call Java function from jni
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Jni: | |
extern "C" JNIEXPORT void JNICALL | |
Java_com_example_javaactivity_initApplicationNative( | |
JNIEnv* env, jobject obj) | |
{ | |
__android_log_print(ANDROID_LOG_VERBOSE, "jni", "jni initApplicationNative"); | |
env->GetJavaVM(&javaVM); | |
jclass cls = env->GetObjectClass(obj); | |
activityClass = (jclass) env->NewGlobalRef(cls); | |
activityObj = env->NewGlobalRef(obj); | |
} | |
void startCamera(jint a,jint b, jint c) | |
{ | |
JNIEnv *env; | |
javaVM->AttachCurrentThread(&env, NULL); | |
jmethodID method = env->GetMethodID(activityClass, "jniCallReady", "(III)V"); | |
env->CallVoidMethod(activityObj, method,a,b,c); | |
} | |
2.Java: | |
initApplicationNative();//init interface in activity | |
define function: | |
public void jniCallReady(int a, int b, int c){ | |
//do st | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment