-
Notifications
You must be signed in to change notification settings - Fork 1k
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
bug: Camera cannot select picture from Redmi Gallery app #2060
Comments
I got the same problem with you. |
The same problem I'm facing |
As no one from the Capacitor team has replied, I'll at least give you a workaround.
const fs = require("fs");
const f =
"node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java";
fs.readFile(f, "utf8", function(err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(
"String filename = contentUri.getLastPathSegment()",
'String filename = "file"'
);
fs.writeFile(f, result, "utf8", function(err) {
if (err) return console.log(err);
});
}); As you can see, this fix is very fragile as it relies on the specific
"scripts": {
"build": "ng build --prod && npx cap sync",
"postinstall": "node patch-camera.js" This automatically runs the fix after |
do you know if it's possible to install the miui gallery in a not xiaomi device? |
I haven't tried to install the APK manually but the app doesn't seem to be available at the Play Store. The problem is this Gallery is the default one for Xiaomi/Redmi users and while the hack is simple, it's not a long-term solution as we have to check the source code with each release to make sure it doesn't break. We ran into this issue immediately after migrating from Cordova but hoped it would be fixed quickly. |
Hello, I am facing this same problem with xiaomi. Our business really needs the camera and our customers are complaining. I think I will try this workaround, but is there any prediction of a definitive solution? |
This worked for me, hope we could get "not patched" solution soon :) |
I can confirm the same issue. Picking an image via the default Xiaomi gallery app results in a "Unable to process image" error. Other gallery apps seem to work, but its a blocker for us since most people with xiaomi devices use the default gallery app. The patched version and the old cordova plugin work for now |
same issue on Xiaomi gallery |
I acknowledge the exactly same issue on my Xiaomi phone while selecting photo from the gallery. Here is my adb log.
|
This fix is working for me, thanks. |
I also have the same problem, when I upload a file from the gallery (the default xiaomi application) it doesn't work, but when I use the default Google Photos app it works Note: the device that I use redmi note 8 |
same issue on Xiaomi gallery |
same issue |
Works!!! Thanks @jirifranc 😄 |
The problem seems to be the encoded URI. The aforementioned line `String filename = contentUri.getLastPathSegment()` is really the real point of failure. On a redmi phone (maybe some others too?), the `contentUri` points to something like `content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FDCIM%2FCamera%2FIMG_20210301_082750.jpg`. So you see the encoded part. `getLastPathSegment()` extract the whole `%2Fstorage%2Femulated%2F0%2FDCIM%2FCamera%2FIMG_20210301_082750.jpg` part, then decodes and returns it. Eventually, the follow outFile got a path like `...package..name.../cache/storage/emulated/0/DCIM/Camera/IMG_20210301_082750.jpg`, and you see where it crashes. I'm not sure if I'm doing it the tidy way, it's the most straightforward way I can think of.
The patch no longer works for me... "@capacitor/android": "^2.4.6", |
Same here |
I've updated Capacitor (core, android, and cli) in our app to 2.4.7 and the patch is still working. Please open the file You can also replace the line according to @eidng8's fix above which hopefully gets merged into Capacitor 3. |
There are certainly a lot of markets where Xiaomi and Redmi phones are commonplace – so much so in my case, that about 40% of my Android users use one. I'm really surprised, especially with a PR outstanding, that the Capacitor team isn't merging it, nor commenting on the issue. |
should be fixed on latest version @capacitor/camera plugin (requires capacitor 3) if you still face the issue, create a new issue on https://github.com/ionic-team/capacitor-plugins/issues and provide a sample app where it can be reproduced |
I encountered this issue on an old Samsung Galaxy J3, the problem persisted even after an upgrade to capacitor@3. I downgraded the capacitor back to v2, as I have a problem debug the native code of the plugins in v3, and found out the exception is thrown in code that corrects the orientation of the image. SolutionBy disabling rotation with Further investigationI got a
from the by digging deeper, it turned out, that the failing code was
I'm a newbie in Android development, but it seems that the Samsung Gallery does not provide a regular file URI, thus the Camera plugin must use Additional informationsI checked the capacitor v3 Camera plugin source code and it seems to me that it is exposed to the same issue by using
which might be necessary for the Camera plugin to work correctly, but on Capacitor v2, the Camera plugin worked even without this variable. |
@czabaj I also confirmed the same issue on a newer galaxy S10. |
We've also had a few users also state that image uploading is not working across the Samsung device list only; Pixels seem to be unaffected by this. Not to repeat what @czabaj has said, but I'm also thinking it's to do with Samsung's photo gallery returning incorrectly, although the specific error i get is As a temporary work around, you can turn the lines here in the plugin (android/capacitor-camera/src/main/java/com.capacitorjs.plugins.camera/ImageUtils) to the following: if (orientation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
return transform(bitmap, matrix);
} else { and rebuilding should allow it to work for now. |
Thanks Matt for your temporary fix. Yesterday I had this issue affect my personal Pixel 3 XL too, though now I am having trouble reproducing it. At the least I can confirm it does seem to happen consistently on Samsung phones. There is a pull request with a fix too: ionic-team/capacitor-plugins@1bde69c |
On Samsung 21 I get the error: (via logcat in android studio)
This happens when (as a user) I attempt to add an image from the stock gallery. WORKS with camera |
This fix works for me with a Xiaomi. Does anyone knows if the Capacitor team is on it ? |
thank you buddy, that did the job ! |
After Capacitor upgrade to v2.5.0 mix of workarounds mentioned above helped us with issue on Xiaomi devices.
|
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 Capacitor, please create a new issue and ensure the template is fully filled out. |
Bug Report
Capacitor Version
npx cap doctor
output:Installed Dependencies:
@capacitor/ios not installed
@capacitor/core 1.2.1
@capacitor/cli 1.2.1
@capacitor/android 1.2.1
Affected Platform(s)
Current Behavior
Using the Camera plugin on Android Redmi phones, when a picture is selected in the Gallery app, this error is thrown: Unable to process image. It doesn't manifest itself with other apps (e.g. File Manager) and also there was no problem with the Cordova plugin which we used before upgrading to Capacitor.
Expected Behavior
Users are able to use the default Gallery app to select their pictures on Redmi phones.
Sample Code or Sample Application Repo
This is the config we use:
const options: CameraOptions = { quality: 30, resultType: CameraResultType.Uri, allowEditing: false, source: CameraSource.Photos, };
Reproduction Steps
Configure the Camera plugin to return a Uri and use the option to select a picture from gallery instead of taking a new photo.
Other Technical Details
Other Information
I suspect the bug concerns other MIUI devices, such as Xiaomi phones. I managed to track down the problem to saveTemporaryImage method in Camera.java. contentUri.getlastPathSegment tries to select the filename and a copy of the file is created in the cacheDir.
However, contentUri from the Gallery app has this format:
content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FDCIM%2FCamera%2FIMG_20191013_191506.jpg
while the other apps return unescaped slashes in the path, e.g.
content://com.mi.android.globalFileexplorer.myprovider/external_files/DCIM/Camera/IMG_20191013_191506.jpg
I created an easy solution for our app (using a random filename) but this is probably a symptom of a more serious issue and I don't know what the proper fix would be. Is it enough to just unescape the path?
The text was updated successfully, but these errors were encountered: