We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2762

Summary: Use SDL_DropEvent to retrieve file path on Android
Product: SDL Reporter: noxalus
Component: eventsAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus, philipp.wiesemann
Version: HG 2.1Keywords: target-2.0.4, triage-2.0.4
Hardware: All   
OS: Android (All)   
Bug Depends on:    
Bug Blocks: 3181    
Attachments: SDL Activity.java: I added a method named "onNativeDropFile" and call at the end of "onCreate" method. | SDL_android.c: I added the native function "Java_org_libsdl_app_SDLActivity_onNativeDropFile".
Patch.

Description noxalus 2014-10-22 13:43:50 UTC
Created attachment 1911 [details]
SDL Activity.java: I added a method named "onNativeDropFile" and call at the end of "onCreate" method. | SDL_android.c: I added the native function "Java_org_libsdl_app_SDLActivity_onNativeDropFile".

When we open file into a SDL application with another application using "Open with" command, we don't have any way to retrieve the file path pass as argument. We could manage this into the Activity that extends from SDLActivity, but, for me, it's the work of SDL to manage that.

On iOS, into the file SDL_uikitappdelegate.m, we can see (line 275) that it uses SDL_SendDropFile function to trigger an SDL_DropEvent with the filename.

I would like the same behaviour for Android, so I updated the SDL source code (default branch, rev. 9176) to allow that.
Comment 1 noxalus 2014-10-22 14:27:19 UTC
Created attachment 1912 [details]
Patch.
Comment 2 Philipp Wiesemann 2014-10-24 09:09:40 UTC
Thank you for working on an implementation.

There is small fault in the patch because getPath() may return null for invalid URIs. [1] This may lead to a crash at least in SDL_SendDropFile() at SDL_strdup().

[1] http://developer.android.com/reference/android/net/Uri.html#getPath%28%29
Comment 3 Ryan C. Gordon 2015-02-19 05:22:19 UTC
Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!
Comment 4 Ryan C. Gordon 2015-04-07 04:57:57 UTC
(sorry if you get a lot of copies of this email, I'm marking several bugs at once)

Marking bugs for the (mostly) final 2.0.4 TODO list. This means we're hoping to resolve this bug before 2.0.4 ships if possible. In a perfect world, the open bug count with the target-2.0.4 keyword is zero when we ship.

(Note that closing a bug report as WONTFIX, INVALID or WORKSFORME might still happen.)

--ryan.
Comment 5 Ryan C. Gordon 2015-05-27 00:37:49 UTC
I added the null check that Philipp requested and put this patch in revision control as  https://hg.libsdl.org/SDL/rev/d86771e28c51 ...thanks!

--ryan.