-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(camera) Multiple selection not working on some Android devices #823
Comments
@dragermrb did you solve this? |
I changed the code to use |
Hi @HarelM In my case I have chosen to use a hook that changes |
I'm comparing the code in this plugin to cordova's camera plugin and I don't see Currently I'm using I'm not sure what the right solution is in this case... :-/ |
You can use hooks to apply patch after capacitor sync. See docs. You can define them in On file {
"name": "My app",
"integrations": {
"capacitor": {}
},
"type": "angular",
"hooks": {
"capacitor:sync:after": "./hooks/fix-android-image-picker.js"
}
} Then, create #!/usr/bin/env node
fs = require('fs');
// Update @capacitor/camera plugin to use Intent.ACTION_OPEN_DOCUMENT
var targetFile = 'node_modules/@capacitor/camera/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java';
var pattern = 'Intent.ACTION_PICK';
var replacement = 'Intent.ACTION_OPEN_DOCUMENT';
module.exports = function (ctx) {
console.log('[Hook]: Fix android image picker');
if (ctx.build.platform === 'android') {
if (fileExists(targetFile)) {
console.log(' - - Fixing file', targetFile);
replaceInFile(targetFile, pattern, replacement);
console.log(' - - - File fixed!');
}
} else {
console.log(' - - Skipped!');
}
};
// function to test if file exists
function fileExists(filePath) {
try {
return fs.statSync(filePath).isFile();
} catch (err) {
return false;
}
}
// function to replace pattern in file
function replaceInFile(filePath, pattern, replacement) {
var file = fs.readFileSync(filePath, 'utf8');
var result = file.replace(pattern, replacement);
fs.writeFileSync(filePath, result, 'utf8');
} |
@dragermrb THANKS!! this is super useful! (although a bit more complicated than |
This comment was marked as abuse.
This comment was marked as abuse.
I've opened a PR to push this fix into this repo: #1549 |
The Camera plugin version 6 now uses the Android Photo Picker instead of using |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out. |
Bug Report
On android, method
pickImages()
(andpickImage()
too) usesIntent.ACTION_PICK
with extra dataIntent.EXTRA_ALLOW_MULTIPLE
set to true, butACTION_PICK
is not documented to supportEXTRA_ALLOW_MULTIPLE
.Specifically:
Selecting multiple photos on some devices (Oppo/Realme for example) doesn't work.
Switch
Intent.ACTION_PICK
toIntent.ACTION_OPEN_DOCUMENT
can solve the problem.Plugin(s)
Capacitor Version
Platform(s)
Current Behavior
Selecting multiple photos on some devices (Oppo/Realme for example) doesn't work.
Expected Behavior
Selecting multiple photos on some devices (Oppo/Realme for example) does work.
Additional Context
The text was updated successfully, but these errors were encountered: