我试图通过根据下面的代码设置字节数组参数来通过 JNI 调用 java 方法。
extern "C"
JNIEXPORT void JNICALL
Java_test_example_test_MainActivity_testOnProgress(JNIEnv *env, jobject instance,
jobject callback) {
//declare ref java class
jclass jClassTestCallBack = env->GetObjectClass(callback);
//declare java method id
jmethodID jMethodIdOnProgress = env->GetMethodID(jClassTestCallBack,"onProgress","([B)V");
//check null
if(jMethodIdOnProgress == 0){
return;
}
jbyteArray result = env->NewByteArray(10);
env->CallVoidMethod(callback,jMethodIdOnProgress,result);
}
Run Code Online (Sandbox Code Playgroud)
在java中。
public class MainActivity extends AppCompatActivity {
private final String TAG = getClass().getSimpleName();
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
}
/**
* A native method that is …Run Code Online (Sandbox Code Playgroud)