mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-08-27 09:01:34 +00:00
filesystem: Implement SDL_GetExeName() for all platforms.
(cherry picked from commit d7ba3efe6b)
This commit is contained in:
@@ -2848,6 +2848,43 @@ int SDL_GetAndroidSDKVersion(void)
|
||||
return sdk_version;
|
||||
}
|
||||
|
||||
char *SDL_GetAndroidPackageName(void)
|
||||
{
|
||||
// this doesn't currently cache this, because it's only used by SDL_GetExeName, which _does_ cache it.
|
||||
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(SDL_FUNCTION);
|
||||
|
||||
JNIEnv *env = Android_JNI_GetEnv();
|
||||
if (!LocalReferenceHolder_Init(&refs, env)) {
|
||||
LocalReferenceHolder_Cleanup(&refs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// context = SDLActivity.getContext();
|
||||
jobject context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
|
||||
if (!context) {
|
||||
SDL_SetError("Couldn't get Android context!");
|
||||
LocalReferenceHolder_Cleanup(&refs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// fileObj = context.getFilesDir();
|
||||
jmethodID mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context), "getPackageName", "()Ljava/lang/String;");
|
||||
jstring jstr = (jstring)(*env)->CallObjectMethod(env, context, mid);
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
LocalReferenceHolder_Cleanup(&refs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *cstr = (*env)->GetStringUTFChars(env, jstr, NULL);
|
||||
char *retval = cstr ? SDL_strdup(cstr) : NULL;
|
||||
(*env)->ReleaseStringUTFChars(env, jstr, cstr);
|
||||
|
||||
LocalReferenceHolder_Cleanup(&refs);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
bool SDL_IsAndroidTablet(void)
|
||||
{
|
||||
JNIEnv *env = Android_JNI_GetEnv();
|
||||
|
||||
@@ -153,6 +153,8 @@ int SDL_GetAndroidSDKVersion(void);
|
||||
bool SDL_IsAndroidTablet(void);
|
||||
bool SDL_IsAndroidTV(void);
|
||||
|
||||
char *SDL_GetAndroidPackageName(void); // this is a SDL_malloc'd string the caller will own.
|
||||
|
||||
// File Dialogs
|
||||
bool Android_JNI_OpenFileDialog(SDL_DialogFileCallback callback, void *userdata,
|
||||
const SDL_DialogFileFilter *filters, int nfilters, bool forwrite,
|
||||
|
||||
Reference in New Issue
Block a user