GoogleChromeLabs / GoogleChromeLabs/bubblewrap
Add a way to disable `android.intent.action.SEND_MULTIPLE`
- Dominant language
- TypeScript
- Stars
- 3.1k
- Forks
- 319
- PR merge metrics
- No merged PRs in 30d
Description
**Description**
I would like to be able to use the share API to receive only one file (the shortcut to my app should not be displayed when multiple images are selected for instance).
**Current state**
Currently if the `twa-manifest.json` specifies that a file is accepted, it will always add `android.intent.action.SEND_MULTIPLE` to the intent filter
https://github.com/GoogleChromeLabs/bubblewrap/blob/83435bf4d73ad74f4d758d1f1f858b51268b3ea7/packages/core/src/lib/TwaGenerator.ts#L358-L359
**Describe the solution you'd like**
Add an option to `twa-manifest.json` to be able to opt out of this behavior.
For instance `sendOnlyOneFile`:
```json
"shareTarget": {
"action": "my_url",
"method": "POST",
"enctype": "multipart/form-data",
"params": {
"sendOnlyOneFile": true,
"files": [
{
"name": "images",
"accept": [
"image/*"
]
}
]
}
```
Implemented like this (so has not to be a breaking change):
```ts
if (twaManifest.shareTarget?.params?.files) {
if (!twaManifest.shareTarget.params.sendOnlyOneFile){
shareTargetIntentFilter.actions.push('android.intent.action.SEND_MULTIPLE');
}
for (const file of twaManifest.shareTarget.params.files) {
file.accept.forEach((accept) => shareTargetIntentFilter.mimeTypes.push(accept));
}
}
```
**Alternatives you've considered**
Manually alter the AndroidManifest. However it is not recommended:
> :warning: : Bubblewrap doesn't expect the generated Android project to be updated using external editors. Any files added manually to the Android project will be deleted or overwritten when update is executed. Changes to twa-manifest.json are preserved.
Contributor guide
Assessment
This issue has not been assessed yet.