# HG changeset patch # User Michael Pavone # Date 1447137276 28800 # Node ID 75453bf2ffac968c701c268b35f36f7958cdecc4 # Parent 415bb1911bd2f50a00ab44f98486eec173cf3973 SDL_AndroidGetExternalStoragePath did not do what I thought. Use JNI directly to call Environment.getExternalStorageDirectory diff -r 415bb1911bd2 -r 75453bf2ffac menu.c --- a/menu.c Mon Nov 09 21:34:32 2015 -0800 +++ b/menu.c Mon Nov 09 22:34:36 2015 -0800 @@ -51,6 +51,42 @@ buf[maxchars-1] = 0; } +#ifdef __ANDROID__ +#include +#include +char *get_external_storage_path() +{ + static char *ret; + if (ret) { + return ret; + } + JNIEnv *env = SDL_AndroidGetJNIEnv(); + if ((*env)->PushLocalFrame(env, 8) < 0) { + return NULL; + } + + jclass Environment = (*env)->FindClass(env, "android/os/Environment"); + jmethodID getExternalStorageDirectory = + (*env)->GetStaticMethodID(env, Environment, "getExternalStorageDirectory", "()Ljava/io/File;"); + jobject file = (*env)->CallStaticObjectMethod(env, Environment, getExternalStorageDirectory); + if (!file) { + goto cleanup; + } + + jmethodID getAbsolutePath = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, file), + "getAbsolutePath", "()Ljava/lang/String;"); + jstring path = (*env)->CallObjectMethod(env, file, getAbsolutePath); + + char const *tmp = (*env)->GetStringUTFChars(env, path, NULL); + ret = strdup(tmp); + (*env)->ReleaseStringUTFChars(env, path, tmp); + +cleanup: + (*env)->PopLocalFrame(env, NULL); + return ret; +} +#endif + void * menu_write_w(uint32_t address, void * context, uint16_t value) { m68k_context *m68k = context; @@ -63,7 +99,7 @@ menu->curpath = strdup(menu->curpath); } else { #ifdef __ANDROID__ - menu->curpath = strdup(SDL_AndroidGetExternalStoragePath()); + menu->curpath = strdup(get_external_storage_path()); #else menu->curpath = strdup(get_home_dir()); #endif