Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android asset path fix + debug mem Ref include fix for gcc + Linux multisampling support #804

Merged
merged 8 commits into from
Jan 25, 2013
37 changes: 25 additions & 12 deletions gameplay/src/PlatformAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,22 +974,35 @@ int Platform::enterMessagePump()
}
GP_ASSERT(env);

// Get the package name for this app from Java.
jclass clazz = env->GetObjectClass(activity->clazz);
jmethodID methodID = env->GetMethodID(clazz, "getPackageName", "()Ljava/lang/String;");
jobject result = env->CallObjectMethod(activity->clazz, methodID);

const char* packageName;
/* Get external files directory on Android; this will result in a directory where all app files
* should be stored, like /mnt/sdcard/android/<package-name>/files/
*/
jboolean isCopy;
packageName = env->GetStringUTFChars((jstring)result, &isCopy);
jvm->DetachCurrentThread();

jclass clazz = env->GetObjectClass(activity->clazz);
jmethodID methodGetExternalStorage = env->GetMethodID(clazz, "getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;");

jclass clazzFile = env->FindClass("java/io/File");
jmethodID methodGetPath = env->GetMethodID(clazzFile, "getPath", "()Ljava/lang/String;");

// Now has java.io.File object pointing to directory
jobject objectFile = env->CallObjectMethod(activity->clazz, methodGetExternalStorage, NULL);

// Now has String object containing path to directory
jstring stringExternalPath = static_cast<jstring>(env->CallObjectMethod(objectFile, methodGetPath));
const char* externalPath = env->GetStringUTFChars(stringExternalPath, &isCopy);

// Set the default path to store the resources.
std::string assetsPath = "/mnt/sdcard/android/data/";
assetsPath += packageName;
assetsPath += "/";
std::string assetsPath(externalPath);
if (externalPath[strlen(externalPath)-1] != '/')
assetsPath += "/";

FileSystem::setResourcePath(assetsPath.c_str());


// Release string data
env->ReleaseStringUTFChars(stringExternalPath, externalPath);
jvm->DetachCurrentThread();

// Get the asset manager to get the resources from the .apk file.
__assetManager = activity->assetManager;

Expand Down