1. For the local static method public static native String getStr(); corresponding to C/C++ code, there is no need to add the static keyword.
2. for static methods. The second parameter: jclass. indicates the calling class.
3. for non-static methods. The second parameter: jobject represents the class instance.
4. for multiple parameters.
Well, for example, if there are two ini, then they are: "(II)V"); One: "(I)V");
Here is an example
c/c++ code< /p>
JNIEXPORT jstring JNICALL Java_com_permadi_testjni_JNIDemo_getStr(JNIEnv *env,
jclass obj) {
jmethodID onMapSurfaceCreate = env->GetMethodID(obj, "fsum", "(II )V");
jobject mFileDescriptor = env->NewObject(obj, onMapSurfaceCreate);
env->CallVoidMethod(mFileDescriptor, onMapSurfaceCreate, 1, 2);
return env->NewStringUTF("I'm from C!");
}
java code:
import android.util.Log ;
public class JNIDemo {
// Local static method
public static native String getStr();
// Local method
public native int getCint(String str);
// Callback function
private void fsum( int i, int j){
< p> Log.e("aaaa", "aaaaa");}
static {
System.loadLibrary("TestJni");
p>}
}