GameCorder.net

このエントリーをはてなブックマークに追加

How to convert string to jstring in jni

How to convert string to jstring in jni.
We can use JNIEnv function.
NewStringUTF Let's see example.


JNIEXPORT jstring JNICALL Java_org_cocos2dx_cpp_AppActivity_text(JNIEnv *env,jobject thiz)
{
    // get scene extend class
    MenuScene* scene = dynamic_cast(cocos2d::CCDirector::sharedDirector()->getRunningScene()->getChildByTag(MenuScene::TAG));
    // convert jstring use NewStringUTF
    return (env)->NewStringUTF(scene->getString.c_str());
}
		

In example.Funtion return jstring.
scene class object function getString return std::string.
I use JNIEnv NewStringUTF return jstring from string const char