Android: Added basic drop file support (thanks, "noxalus"!).
authorRyan C. Gordon <icculus@icculus.org>
Tue, 26 May 2015 20:36:45 -0400
changeset 9640d86771e28c51
parent 9639 044cafe15108
child 9641 425c1100b496
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.
android-project/src/org/libsdl/app/SDLActivity.java
src/core/android/SDL_android.c
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Tue May 26 20:22:14 2015 -0400
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Tue May 26 20:36:45 2015 -0400
     1.3 @@ -173,6 +173,17 @@
     1.4          mLayout.addView(mSurface);
     1.5  
     1.6          setContentView(mLayout);
     1.7 +        
     1.8 +        // Get filename from "Open with" of another application
     1.9 +        Intent intent = getIntent();
    1.10 +
    1.11 +        if (intent != null && intent.getData() != null) {
    1.12 +            String filename = intent.getData().getPath();
    1.13 +            if (filename != null) {
    1.14 +                Log.v("SDL", "Get filename:" + filename);
    1.15 +                SDLActivity.onNativeDropFile(filename);
    1.16 +            }
    1.17 +        }
    1.18      }
    1.19  
    1.20      // Events
    1.21 @@ -397,6 +408,7 @@
    1.22      public static native void nativeQuit();
    1.23      public static native void nativePause();
    1.24      public static native void nativeResume();
    1.25 +    public static native void onNativeDropFile(String filename);
    1.26      public static native void onNativeResize(int x, int y, int format, float rate);
    1.27      public static native int onNativePadDown(int device_id, int keycode);
    1.28      public static native int onNativePadUp(int device_id, int keycode);
     2.1 --- a/src/core/android/SDL_android.c	Tue May 26 20:22:14 2015 -0400
     2.2 +++ b/src/core/android/SDL_android.c	Tue May 26 20:36:45 2015 -0400
     2.3 @@ -141,6 +141,16 @@
     2.4      __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init() finished!");
     2.5  }
     2.6  
     2.7 +/* Drop file */
     2.8 +void Java_org_libsdl_app_SDLActivity_onNativeDropFile(
     2.9 +                                    JNIEnv* env, jclass jcls,
    2.10 +                                    jstring filename)
    2.11 +{
    2.12 +    const char *path = (*env)->GetStringUTFChars(env, filename, NULL);
    2.13 +    SDL_SendDropFile(path);
    2.14 +    (*env)->ReleaseStringUTFChars(env, filename, path);
    2.15 +}
    2.16 +
    2.17  /* Resize */
    2.18  JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeResize(
    2.19                                      JNIEnv* env, jclass jcls,