java代码
private static String getString(){
return string;
}
C++代码
static string getDeviceModelJNI() {
string retValue = "";
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
JniMethodInfo minfo;//定义Jni函数信息结构体
jstring jobj;
bool isHave = JniHelper::getStaticMethodInfo(minfo,"com/wangniu/hlddz/SGddzActivity","getDeviceModel", "()Ljava/lang/String;");
if (isHave) {
jobj = (jstring)minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID);
}
retValue = JniHelper::jstring2string(jobj);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
retValue = "MAC";
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
retValue = "Win32";
#endif
return retValue;
}
};

本文介绍如何在C++中调用Java代码,尤其是获取返回的String类型的方法。通过示例展示了在Android、Mac及Windows平台上的不同实现方式。
最低0.47元/天 解锁文章
4617

被折叠的 条评论
为什么被折叠?



