Skip to content

Commit

Permalink
Android: Added basic drop file support (thanks, "noxalus"!).
Browse files Browse the repository at this point in the history
This lets SDL-based apps respond to "Open With" commands properly, as they
can now obtain the requested path via a standard SDL dropfile event.

This is only checked on startup, so apps don't get drop events at any other
time, even if Android supports that, but this is still a definite
improvement.

Fixes Bugzilla #2762.
  • Loading branch information
icculus committed May 27, 2015
1 parent ae6555d commit 72a244d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -173,6 +173,17 @@ public void onClick(DialogInterface dialog,int id) {
mLayout.addView(mSurface);

setContentView(mLayout);

// Get filename from "Open with" of another application
Intent intent = getIntent();

if (intent != null && intent.getData() != null) {
String filename = intent.getData().getPath();
if (filename != null) {
Log.v("SDL", "Get filename:" + filename);
SDLActivity.onNativeDropFile(filename);
}
}
}

// Events
Expand Down Expand Up @@ -397,6 +408,7 @@ boolean sendCommand(int command, Object data) {
public static native void nativeQuit();
public static native void nativePause();
public static native void nativeResume();
public static native void onNativeDropFile(String filename);
public static native void onNativeResize(int x, int y, int format, float rate);
public static native int onNativePadDown(int device_id, int keycode);
public static native int onNativePadUp(int device_id, int keycode);
Expand Down
10 changes: 10 additions & 0 deletions src/core/android/SDL_android.c
Expand Up @@ -141,6 +141,16 @@ JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init() finished!");
}

/* Drop file */
void Java_org_libsdl_app_SDLActivity_onNativeDropFile(
JNIEnv* env, jclass jcls,
jstring filename)
{
const char *path = (*env)->GetStringUTFChars(env, filename, NULL);
SDL_SendDropFile(path);
(*env)->ReleaseStringUTFChars(env, filename, path);
}

/* Resize */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeResize(
JNIEnv* env, jclass jcls,
Expand Down

0 comments on commit 72a244d

Please sign in to comment.