ionic-team / ionic-team/capacitor-plugins
Share feature: Ability to specify the mime type for Android files
- Dominant language
- Java
- Stars
- 678
- Forks
- 685
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 3
Description
## Feature Request
### Plugin
share
### Description
The app I am working on has an uncommon file extension, and `android.webkit.MimeTypeMap` quite reasonably does not know what it should map to. Unfortunately, some apps (WhatsApp for instance) do not seem to respect sharing files of type `*/*` and the file I wish to share is being discarded making a rather useless text-only share.
### Platform(s)
Android
### Preferred Solution
I would like some way to be able to include a more accurate filetype (in my case `application/octet-stream` is sufficient) when I call `Share.share(...)`. This could be implemented as an optional object syntax in the `files` array of `ShareOptions` e.g.
```
Share.share({
...
files: [
{file: "file://location/", mimeType: "application/octet-stream"},
{file: "file://location/", mimeType: "application/octet-stream"},
]
}
```
### Alternatives
* Allow the user to pass a custom MIME type map to the Share plugin prior to calling it.
* Incorporate a `defaultMimeType` in `ShareOptions` that is used whenever `android.webkit.MimeTypeMap` is unable to determine the MIME type from the extension.
* As a proof of concept I have manually changed the fallback MIME type in `SharePlugin.java` in my build area to change it from `*/*` to `application/octet-stream`, though this is not a long-term solution. I.e. in the place where MIME types are inferred:
```
String type = getMimeType(file);
if (type == null || filesList.size() > 1) {
type = "application/octet-stream";
}
```
And this causes the share approach to work satisfactorily with WhatsApp.
Contributor guide
Assessment
This issue has not been assessed yet.