microsoft / WSA

Developer-related issues and feature requests for Windows Subsystem for Android
MIT License
1.51k stars 826 forks source link

Unsupported Mimes Types when Drag'n Drop file on app #335

Open hgourvest opened 1 year ago

hgourvest commented 1 year ago

Steps to reproduce

I checked whether I could perform a drag-and-drop operation with the file types supported by my application, which is a comic book reader. It appears that two file types are not supported by WSA. I used the filter below to capture the mime types sent. No event is sent for files with extension .cb7 or .cbt

<intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="*/*"/>
</intent-filter>

✔️ Expected Behavior

I expect to receive an event for files with extension cb7 and cbt

here's the definition of the file types I expect to open

".cb7" (ComicBook in 7z format), mime type: "application/x-cb7" ".cbt" (ComicBook in tar format), mime type: "application/x-cbt"

❌ Actual Behavior

I'm not receiving any events in my application

Other Software

No response

Please specify the version of Windows Subsystem for Android

2305.40000.5.0

jaholme commented 1 year ago

If you add a specific mime type instead of */* does the functionality work?

hgourvest commented 1 year ago

It makes no difference.

kevinkieselbach commented 1 year ago

The issue is that we use https://developer.android.com/reference/android/webkit/MimeTypeMap#getMimeTypeFromExtension(java.lang.String) to convert the file extension to a MIME type for resolving the ACTION_SEND intent, and .cb7 and .cbt are custom file extensions that cannot be mapped to a MIME type. I verified .7z and .tar work. We can make custom file extensions work by mapping any unknown file extension to */*. Just make sure your intent filter supports */* since we can't map to custom MIME types like "application/x-cb7". This update will be in our 2306 release.

hgourvest commented 1 year ago

I see, thanks for taking the time to investigate.

As an alternative, I suggest mapping the unknown extensions to the "application/octet-stream" mime type.

kevinkieselbach commented 1 year ago

https://developer.android.com/reference/android/content/Intent#ACTION_SEND says to "use */* if the MIME type is unknown (this will only allow senders that can handle generic data streams)."