Add a way to disable android.intent.action.SEND_MULTIPLE
#592
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
bubblewrap/packages/core/src/lib/TwaGenerator.ts
Lines 358 to 359 in 83435bf
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
:
"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):
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:
⚠️ : 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.