fixed #1702:modify writable path to the return value of Context.getFilesDirectory()

This commit is contained in:
minggo 2013-02-07 14:11:23 +08:00
parent 404cdf1122
commit 59c1f33ad5
4 changed files with 25 additions and 1 deletions

View File

@ -159,7 +159,7 @@ string CCFileUtilsAndroid::getWritablePath()
// Fix for Nexus 10 (Android 4.2 multi-user environment)
// the path is retrieved through Java Context.getCacheDir() method
string dir("");
const char *tmp = getCacheDirectoryJNI();
const char *tmp = getFileDirectoryJNI();
if (tmp)
{

View File

@ -23,6 +23,7 @@ THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Locale;
@ -48,6 +49,7 @@ public class Cocos2dxHelper {
private static boolean sAccelerometerEnabled;
private static String sPackageName;
private static String sCacheDirectory;
private static String sFileDirectory;
private static Cocos2dxHelperListener sCocos2dxHelperListener;
@ -62,6 +64,7 @@ public class Cocos2dxHelper {
Cocos2dxHelper.sPackageName = applicationInfo.packageName;
Cocos2dxHelper.sCacheDirectory = pContext.getCacheDir().getAbsolutePath();
Cocos2dxHelper.sFileDirectory = pContext.getFilesDir().getAbsolutePath();
Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir);
Cocos2dxHelper.nativeSetExternalAssetPath(Cocos2dxHelper.getAbsolutePathOnExternalStorage(applicationInfo, "assets/"));
@ -98,6 +101,10 @@ public class Cocos2dxHelper {
return Cocos2dxHelper.sCacheDirectory;
}
public static String getCocos2dxWritablePath() {
return Cocos2dxHelper.sFileDirectory;
}
public static String getCurrentLanguage() {
return Locale.getDefault().getLanguage();
}

View File

@ -147,6 +147,22 @@ extern "C" {
return 0;
}
const char * getFileDirectoryJNI() {
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getCocos2dxWritablePath", "()Ljava/lang/String;")) {
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
CCString *ret = new CCString(JniHelper::jstring2string(str).c_str());
ret->autorelease();
t.env->DeleteLocalRef(str);
return ret->m_sString.c_str();
}
return 0;
}
const char* getCurrentLanguageJNI() {
JniMethodInfo t;

View File

@ -36,6 +36,7 @@ extern "C" {
extern const char * getCurrentLanguageJNI();
extern const char * getPackageNameJNI();
extern const char * getCacheDirectoryJNI();
extern const char * getFileDirectoryJNI();
extern void enableAccelerometerJNI();
extern void disableAccelerometerJNI();
extern void setAccelerometerIntervalJNI(float interval);