diff --git a/cocos/base/ccUTF8.h b/cocos/base/ccUTF8.h index c30a4cf020..45d7c59413 100644 --- a/cocos/base/ccUTF8.h +++ b/cocos/base/ccUTF8.h @@ -80,7 +80,7 @@ CC_DLL bool UTF16ToUTF8(const std::u16string& utf16, std::string& outUtf8); * because getStringUTFChars can not pass special emoticon * @param env The JNI Env * @param srcjStr The jstring which want to convert -* @param ret True if convert success, if ret not null +* @param ret True if the conversion succeeds and the ret pointer isn't null * @returns the result of utf8 string */ CC_DLL std::string getStringUTFCharsJNI(JNIEnv* env, jstring srcjStr, bool* ret = nullptr); @@ -90,7 +90,7 @@ CC_DLL std::string getStringUTFCharsJNI(JNIEnv* env, jstring srcjStr, bool* ret * because newStringUTF can not convert special emoticon * @param env The JNI Env * @param srcjStr The std::string which want to convert -* @param ret True if convert success, if ret not null +* @param ret True if the conversion succeeds and the ret pointer isn't null * @returns the result of jstring,the jstring need to DeleteLocalRef(jstring); */ CC_DLL jstring newStringUTFJNI(JNIEnv* env, std::string utf8Str, bool* ret = nullptr); diff --git a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp index cf4264a45d..018e90f303 100644 --- a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp +++ b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp @@ -32,6 +32,8 @@ THE SOFTWARE. #include "deprecated/CCString.h" #include "Java_org_cocos2dx_lib_Cocos2dxHelper.h" +#include "base/ccUTF8.h" + #define LOG_TAG "Java_org_cocos2dx_lib_Cocos2dxHelper.cpp" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) @@ -117,12 +119,13 @@ void showEditTextDialogJNI(const char* title, const char* message, int inputMode jstring stringArg1; if (!title) { + stringArg1 = t.env->NewStringUTF(""); } else { - stringArg1 = t.env->NewStringUTF(title); + stringArg1 = cocos2d::StringUtils::newStringUTFJNI(t.env, title); } - jstring stringArg2 = t.env->NewStringUTF(message); + jstring stringArg2 = cocos2d::StringUtils::newStringUTFJNI(t.env, message); t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2,inputMode, inputFlag, returnType, maxLength); diff --git a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp index e8703f0e0b..5992f7783c 100644 --- a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp +++ b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp @@ -51,6 +51,6 @@ extern "C" { return 0; } std::string pszText = cocos2d::IMEDispatcher::sharedDispatcher()->getContentText(); - return env->NewStringUTF(pszText.c_str()); + return cocos2d::StringUtils::newStringUTFJNI(env, pszText); } }