Android: Added basic drop file support (thanks, "noxalus"!). 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index 5e88108..0c5fa58 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -173,6 +173,17 @@ public class SDLActivity extends Activity {
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
@@ -397,6 +408,7 @@ public class SDLActivity extends Activity {
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);
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index e74e65e..cac0872 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -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,