-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Cannot use saveToPhotoAlbum: true on Android 10 #611
Comments
I also confirm that issue. On Android 9 all features works great, but after update my device to Android 10 I got "Error capturing image" when flag saveToPhotoAlbum is set to the value true. Device: Samsung A40 |
From my understanding, what appears to be happening is that saving to photo album is triggering an access to storage outside the app's permitted storage, as android 10 comes with changes to where the app is permitted to do file operations. It may be possible to fix it with |
Unfortunately
And I got:
|
I downgraded |
Even on an Android 10 phone? |
Yes, I tested this solution on Samsung A40 with Android 10. When I had Android 9 then all camera features worked properly with setting compileSdkVersion=29, but after upgrade to Android 10 I had to downgrade compileSdkVersion. |
@bartdeveloper Appreciate if you could share your git repo link. |
Looks like API 29 requires Scoped Locations There are two current workarounds:
I'm not familiar with this plugin's codebase, but it looks like
It would be nice to know exactly what that error is, and perhaps stacktrace. |
The commit e9aba07 is bad and causes this issue. |
@isamuAsial That commit is not officially released and only exists in master. I would recommend using 4.1.0 which had been voted on and official released for production use. 4.1.0 release does not contain that commit. |
I had white screen issues when trying to use that flag. |
This is the stacktrace that I got in the logcat:
I was ultimately able to resolve the error using the |
We're using 4.1.0 and we have exactly same problem on Android 10 devices. The stacktrace is same as provided by @jwasnoggin above. So it seems production version is affected as well. Cordova CLI: 10.0.0 |
I am having this same issue on API SDK 29, tried adding this snippet to my Android platform in the
Which either causes the app to crash when I accept permissions or do nothing at all. Cordova CLI: 10.0.0 |
Hello, |
Same here. |
Not sure if this is related or not, but v5.0.0 of the plugin fails for me as well with saveToPhotoAlbum set true. For me, it is also failing on my Android 8 test device with the following stack trace:
It appears that the source URI has a content: scheme instead of a file: scheme that writeUncompressedImage() expects. I was able to get it working by changing line 903 of CameraLauncher.java from:
to
openInputStream() is documented to accept both file: and content: schemes, so this change should handle both cases. With this change, saveToPhotoAlbum works again on this Android 8 device. I haven't had a chance to test on any other devices yet. |
Same here. Any solution or workarounds for Android 10 |
With my above change, it is now working for me on my Android 10 device using "cordova-android": "^9.0.0" and "cordova-plugin-camera": "^5.0.0". The options that I am passing in to getPicture() are:
|
Hey @wifisher , |
Isn't the targetSDKVersion set to 29 by cordova-android 9.0.0? |
I am unaware of this. Can you check whether it is 29 or not? |
According to https://cordova.apache.org/announcements/2020/06/29/cordova-android-9.0.0.html the default targetSDKVersion is 29 with cordova-android 9.0.0. I did a test by setting the version in config.xml with the following line: I was able to take a picture and have it appear in the gallery. |
The app I am working on we also have |
You can test my fix by making the change to CameraLauncher.java that I mentioned above. Test by making the change to the file at this location: platforms/android/app/src/main/java/org/apache/cordova/camera. Then build and run. If it works, then your problem is the same as mine. I wouldn't build a release with this change hacked in, but it would be useful to know if it is the same problem or not. It's a small change, but it would be nice to see it come out in a 5.0.1 version of the camera plugin. |
…om camera - Android - saveToPhotoAlbum feature fixed by taken into count content - uri. (writeUncompressedImage method) ( see: apache#611 (comment) ) - make saveToPhotoAlbum future proof by using the MediaStore to insert the taken image - made a method to calculate the compressFormat based on the encodingType (JPEG or PNG) - layout of the performCrop method is adjusted - removed unused rotate variable inside processResultFromGallery method
@wifisher I did made a change to the code. I've read your suggestion of the content uri. You can test the changes with next commands.
Can you test this? After testing I could make a PR for this. Another remark: It should be saved to the photo album, if you take a picture with the camera. Kind regards. |
@PieterVanPoyer I installed your plugin and it appears to be working correctly for me. |
I "solved" this issue by using Capacitor instead of Cordova using https://capacitorjs.com/docs/apis/camera |
@PieterVanPoyer I can confirm that your fix is also working for me. |
@PieterVanPoyer ,
Should updating |
I did make a Pull Request to solve the issue with saveToPhotoAlbum and the camera. #669
I don't think updating (or installing the fork) is possible without updating the Cordova CLI and cordova android version. (Current version of the cli is 10, I believe.) Kind regards |
* GH-341 - GH-577 Fixed the Save Photo To Album starting from camera - Android - saveToPhotoAlbum feature fixed by taken into count content - uri. (writeUncompressedImage method) ( see: #611 (comment) ) - make saveToPhotoAlbum future proof by using the MediaStore to insert the taken image - made a method to calculate the compressFormat based on the encodingType (JPEG or PNG) - layout of the performCrop method is adjusted - removed unused rotate variable inside processResultFromGallery method * Add extra VO class to the plugin.xml * added package declaration to new VO * GH-341 - GH-577 #669 (comment) listen to review
I'm using the latest version of this plugin from master after the above merge but it seems that it doesn't work with android 10, even if I set if (takePicturePermission && saveAlbumPermission) {
takePicture(returnType, encodingType);
} else if (saveAlbumPermission && !takePicturePermission) {
PermissionHelper.requestPermission(this, TAKE_PIC_SEC, Manifest.permission.CAMERA);
} else if (!saveAlbumPermission && takePicturePermission) {
/// ---> I'm getting here which doesn't do anything in android 10...
PermissionHelper.requestPermissions(this, TAKE_PIC_SEC,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE});
} else {
PermissionHelper.requestPermissions(this, TAKE_PIC_SEC, permissions);
} Has anyone else got to this point? Am I missing something? Should I just remove the |
@HarelM I was able to reproduce it. In my testsetup I removed the When I remove this line Kind regards |
Hello @PieterVanPoyer , I have used the latest Camera plugin version and I am facing an issue in which I am unable to upload files from the google drive. I have created an issue in the file plugin repo, but haven't got a reply. If you can look into it. Thanks. |
@PieterVanPoyer Thanks! Seems like this permission is now missing, I have no idea why, I see it on both the camera plugin
But it doesn't get to the manifest.xml file as it used to. |
@HarelM indeed normally the permission must be set by cordova itself. Can you reproduce it in a blank Cordova 10 project in anyway, with just the camera plugin included? |
I'm not sure I can reproduce it on a blank project. but my project is open source and the CI build machine is always a clean start. |
BTW @PieterVanPoyer, after fixing all the permission issues and build issues I still don't see the image I take in the photo gallery so I'm not sure the latest version (after the #669 PR merged here) does fix this bug in all android versions... |
@HarelM I won't be able to test every Android device offcourse. But just to be curious, is the taken picture returned to your app? Do you use DATA_URI or FILE_URI as type? |
I'm using android 9. |
Originally, there was an error thrown and no image was returned. You could try to test with next repo: https://github.com/PieterVanPoyer/cordova-camera-plugin-testing-app/tree/master Then maybe we can pinpoint the issue. Do you test on an emulator or on a real device? |
My bad, I now see the photo I took in the Pictures folder (not the camera folder, which is what google photos is showing). |
No problem. We figured out the permission issue. |
Can anyone help me on this? |
@AleFons is this issue still happening with the latest released version? If not, feel free to close this issue. |
Any updates on this? |
Can't speak for @AleFons, but I encountered the same issue, and the latest version resolved it for me. |
The latest version has solved it for me too. I believe the issue has been solved with Cordova 10. |
@AleFons nice, maybe you should close this issue then? Kind regards Pieter |
This worked for me, it is a great solution |
I have this issue on Android 11. None of the above solutions work! I upgraded to cordova-android 10. That didn't help either. Anyone tried the solutions on Android 11? |
Same Here Does not work on Android 10 or 11 |
Bug Report
Problem
What is expected to happen?
Using
saveToPhotoAlbum: true
should allow the user to take a picture and save a backup to the phone's gallery.What does actually happen?
The plugin instead throws an error on Android 10.
Information
Setting the option to
false
avoids the problem, but then no backup is made.Command or Code
I use these options for
Camera.getPicture()
:Environment, Platform, Device
Android 10, has happened on multiple devices.
Version information
Ionic:
ionic (Ionic CLI) : 4.6.0
Ionic Framework : ionic-angular 3.9.6
@ionic/app-scripts : 3.2.4
Cordova:
cordova (Cordova CLI) : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0, ios 5.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.0.5, cordova-plugin-ionic-webview 2.2.0, (and 18 other plugins)
System:
Android SDK Tools : 26.1.1
NodeJS : v12.16.3
npm : 6.14.4
OS : Linux 4.15
Checklist
The text was updated successfully, but these errors were encountered: