Reputation: 2872
I need to capture an image with my Phonegap app. On iOS everything works fine but on Android (via Phonegap Build) it throws an error with "Error capturing image".
I added the following lines to my config.xml but that doesn't change anything:
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>
<feature name="http://api.phonegap.com/1.0/device" />
<feature name="http://api.phonegap.com/1.0/camera" />
<feature name="http://api.phonegap.com/1.0/file" />
<feature name="http://api.phonegap.com/1.0/media" />
<feature name="http://api.phonegap.com/1.0/network" />
My API call looks like that:
$(document).on('click', '#cameraPreview', function() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
navigator.camera.getPicture(onGetPictureSuccess, onGetPictureFail, {
quality: 40,
sourceType: Camera.PictureSourceType.CAMERA,
destinationType: Camera.DestinationType.FILE_URI,
allowEdit: true,
encodingType: Camera.EncodingType.JPG,
targetWidth: 1000,
targetHeight: 1000,
saveToPhotoAlbum: true,
correctOrientation: 1
});
});
I use Phonegap 3.7 with Phonegap Build.
Upvotes: 6
Views: 4853
Reputation: 339
The permission requirements have changed in different versions of Android and different SDK versions. Make sure you are using the appropriate plugin version for your target OS version.
For anyone seeing this same issue with cordova-camera-plugin <=4.2.0 on Android 10, you can set <preference name="android-targetSdkVersion" value="28" />
See this ticket for more info: https://github.com/apache/cordova-plugin-camera/issues/611
Upvotes: 0
Reputation: 385
Updating cordova-camera-plugin
to version 4.0.2 or higher should fix the problem with saving to the photo album.
Since Android 8, saving a photo in the photo album requires the WRITE_EXTERNAL_STORAGE
permission, but this is not requested by versions of cordova-camera-plugin
older than 4.0.2.
For more information:
Upvotes: 1
Reputation: 299
Check your cordova-camera-plugin version. If it's under 4.0.1, this will be fixed by updating latest version. Otherwise, I have no idea.
This is a known issue and already be fixed. You can see more detail below link. https://issues.apache.org/jira/browse/CB-13781
Upvotes: 2
Reputation: 1
For me, I had to add this permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Upvotes: 0
Reputation: 2872
Ok, now I know the answer. The problem is the saveToPhotoAlbum: true
option. Android doesn't recognize this. When I delete this option everything works fine.
Upvotes: 28