主要接口:
static bool getStaticMethodInfo(JniMethodInfo &methodinfo, const char *className, const char *methodName, const char *paramCode);功能:获取java类相应函数信息,classid、methodid等
jint CallStaticIntMethod(jclass clazz, jmethodID methodID, ...)功能:通过JNIEnv执行调用,返回值为int类型
如: jstring stringArg = methodInfo.env->NewStringUTF(key);//参数转换 int res=methodInfo.env->CallStaticIntMethod(methodInfo.classID, methodInfo.methodID, stringArg,value);//执行传参调用及返回值
例子:
调用java静态函数getInt
static int getInt(const char* key,int value,const char* classPath) { JniMethodInfo methodInfo; if (! JniHelper::getStaticMethodInfo(methodInfo, classPath,"getInt", "(Ljava/lang/String;I)I"))//获取java类相应getInt函数信息 { return -1; } jstring stringArg = methodInfo.env->NewStringUTF(key);//参数转换 int res=methodInfo.env->CallStaticIntMethod(methodInfo.classID, methodInfo.methodID, stringArg,value);//执行传参调用及返回值 methodInfo.env->DeleteLocalRef(stringArg); methodInfo.env->DeleteLocalRef(methodInfo.classID); return res; }