mirror of https://github.com/axmolengine/axmol.git
[android] fixed #683: let getCurrentLanguageJNI() & getPackageNameJNI() return valid pointer
This commit is contained in:
parent
e0b804f2f9
commit
1640e48d5a
|
@ -7,11 +7,13 @@
|
|||
#include <jni.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#define LOG_TAG "CCApplication_android Debug"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
NS_CC_BEGIN;
|
||||
using namespace std;
|
||||
|
||||
// sharedApplication pointer
|
||||
CCApplication * CCApplication::sm_pSharedApplication = 0;
|
||||
|
@ -78,7 +80,7 @@ CCApplication& CCApplication::sharedApplication()
|
|||
|
||||
ccLanguageType CCApplication::getCurrentLanguage()
|
||||
{
|
||||
char* pLanguageName = getCurrentLanguageJNI();
|
||||
const char *pLanguageName = getCurrentLanguageJNI();
|
||||
ccLanguageType ret = kLanguageEnglish;
|
||||
|
||||
if (0 == strcmp("zh", pLanguageName))
|
||||
|
|
|
@ -26,6 +26,7 @@ NS_CC_BEGIN;
|
|||
|
||||
#include "CCCommon.h"
|
||||
#include "jni/SystemInfoJni.h"
|
||||
#include <string>
|
||||
|
||||
#define MAX_PATH 256
|
||||
|
||||
|
@ -133,15 +134,12 @@ string CCFileUtils::getWriteablePath()
|
|||
{
|
||||
// the path is: /data/data/ + package name
|
||||
string dir("/data/data/");
|
||||
char* tmp = getPackageNameJNI();
|
||||
const char *tmp = getPackageNameJNI();
|
||||
|
||||
if (tmp)
|
||||
{
|
||||
dir.append(tmp).append("/");
|
||||
|
||||
// release memory
|
||||
delete [] tmp;
|
||||
|
||||
return dir;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -23,6 +23,7 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
#include "SystemInfoJni.h"
|
||||
#include "JniHelper.h"
|
||||
#include "CCString.h"
|
||||
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
|
@ -39,10 +40,9 @@ using namespace cocos2d;
|
|||
|
||||
extern "C"
|
||||
{
|
||||
char* getPackageNameJNI()
|
||||
const char* getPackageNameJNI()
|
||||
{
|
||||
JniMethodInfo t;
|
||||
char* ret = 0;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t,
|
||||
"org/cocos2dx/lib/Cocos2dxActivity",
|
||||
|
@ -50,21 +50,23 @@ extern "C"
|
|||
"()Ljava/lang/String;"))
|
||||
{
|
||||
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
|
||||
ret = (char*)JniHelper::jstring2string(str).c_str();
|
||||
CCString *ret = new CCString(JniHelper::jstring2string(str).c_str());
|
||||
ret->autorelease();
|
||||
|
||||
LOGD("package name %s", ret);
|
||||
LOGD("package name %s", ret->m_sString.c_str());
|
||||
|
||||
return ret->m_sString.c_str();
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// handle get current language
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
char* getCurrentLanguageJNI()
|
||||
const char* getCurrentLanguageJNI()
|
||||
{
|
||||
JniMethodInfo t;
|
||||
char* ret = 0;
|
||||
|
||||
if (JniHelper::getStaticMethodInfo(t
|
||||
, "org/cocos2dx/lib/Cocos2dxActivity"
|
||||
|
@ -72,11 +74,14 @@ extern "C"
|
|||
, "()Ljava/lang/String;"))
|
||||
{
|
||||
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
|
||||
ret = (char*)JniHelper::jstring2string(str).c_str();
|
||||
CCString *ret = new CCString(JniHelper::jstring2string(str).c_str());
|
||||
ret->autorelease();
|
||||
|
||||
LOGD("language name %s", ret);
|
||||
LOGD("language name %s", ret.c_str());
|
||||
|
||||
return ret->m_sString.c_str();
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,13 @@ THE SOFTWARE.
|
|||
#define __ANDROID_SYSTEM_INFO_JNI_H__
|
||||
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
|
||||
extern "C"
|
||||
|
||||
{
|
||||
extern char* getCurrentLanguageJNI();
|
||||
extern char* getPackageNameJNI();
|
||||
extern const char* getCurrentLanguageJNI();
|
||||
extern const char* getPackageNameJNI();
|
||||
}
|
||||
|
||||
#endif // __ANDROID_SYSTEM_INFO_JNI_H__
|
||||
|
|
Loading…
Reference in New Issue