-->

can i call java method from native code?if so how?

2019-08-20 05:00发布

问题:

I have a Java function which can take variable number of parameters and in JNI I am receiving all the parameters in jobjectArray. But the problem is all the parameters available in String type,but originally thy are of different datatype. So in c/c++ converting them to their original type is not possible. So if i could call some other java method which will make these conversions easy for me.is it possible in to call a java method from native code in JNI?

Please help me out. I am really struck at it from a long time. Thanks in advance.

回答1:

Here's a succinct example: http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html.

Fundamentally you need to look up native objects representing the class and method you want to call, format your arguments, call the appropriate JNIEnv->CallXXX method, and process the resulting value.



回答2:

we can pass the String as a parameter from native code when you callback the java method using env->NewStringUTF(actual parameter).