cordova-plugin-camera
cordova-plugin-camera copied to clipboard
Unable to create bitmap!
Bug Report
Crashlytics is giving us "Unable to create bitmap!" error for some users who try to take a picture.
Problem
An error happens as the user uploads what seems to him as a valid picture and he is stuck on that page because we require a picture.
What is expected to happen?
Just a normal flow of taking a picture and getting it's URL.
What does actually happen?
An error occurs and the user is stuck there "Unable to create bitmap!"
Information
So I don't have more information than what Crashlytics gives me other than the fact that it happens 100% of the time on Android and the below code and environment details.
Command or Code
//Not sure exactly where in the plugin, but here is how we call it.
let options = {
quality : 100,
destinationType: this.camera.DestinationType.DATA_URL,
sourceType: sourcetype,
encodingType: this.camera.EncodingType.JPEG, //0 JPEG
saveToPhotoAlbum: false,
correctOrientation: true,
cameraDirection: 1,//front
allowEdit: false
}
return new Promise((resolve, reject) => {
this.camera.getPicture(options).then(base64 => {
}
}
Environment, Platform, Device
Android, no specific version stands out.
Version information
Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 8.1.0, ios 5.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 5.0.0, (and 26 other plugins)
Checklist
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
I have the same issue on Android 11 (API 30) only. Running on Android 10 (API 29), everything works as normal.
If I try to load an image from the library (sourceType: PHOTOLIBRARY
) I get: Unable to create bitmap!
If I try to take an image from the camera (sourceType: CAMERA
) I get: Attempt to invoke virtual method 'boolean java.io.File.mkdirs()' on a null object reference
(Seems related to #658)
Environment, Platform, Device
Emulated Android 11 - R (API 30)
Using AndroidX setting in my cordova config.xml
: <preference name="AndroidXEnabled" value="true" />
Version information
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 16 other plugins)
Had this happen on a production user too
Mozilla/5.0 (Linux; Android 9; INE-LX2 Build/HUAWEIINE-LX2; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.90 Mobile Safari/537.36
Not much other info. Hopefully this helps
I am still seeing this issue. Any solution for this ?
The storage has changed after Android11, and the APP can only access its own private directory or public directory, and cannot access the private directory of other apps. You call the system’s built-in crop that does not belong to your app, and access to your app’s private directory is not allowed. Please add the following compatible code to the createCaptureFile method. `
if (Build.VERSION.SDK_INT >= 30) { return new File(Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES), fileName); }
`
@epetre is this issue still happening with the latest version?
@PieterVanPoyer Yes I am still facing same issue with latest version.
var options = { quality: 90, destinationType: Camera.DestinationType.DATA_URL, sourceType: 1, encodingType: 1, // JPEG=0 PNG=1 mediaType: Camera.MediaType.PICTURE, allowEdit: true, correctOrientation: true, targetWidth: 480, targetHeight: 480, cameraDirection: 1 };
@xuyonghua Perfect solution , Thank You...!!!!!!
For anyone still facing this issue with ionic 3, or anyu version with this plugin, it only happens when you set the options to
allowEdit: true,
targetWidth: <any value>,
targetHeight: <any value>,
The same mistake (error in JavaScript onFail), different reasons and Solutions
My app runs on an Android 10 AR device
I annotate a line of code which been red highlight error in my android studio Logcat to solve it
// this.cordova.getActivity().getContentResolver().delete(uri, null, null);
Maybe my device just doesn't allow cordova to delete cacah.
A suggestion, try view Android studio logcat
resolved,thx~~
@xuyonghua sir can you tell me where we put above code?
I am getting the same issue "unable to create bitmap" device : realme 5 pro Android 11 Cordova : cordova-android 12
After some investigation found that the when
allowEdit:true
app needs Permission to "Public pictures" directory, but the camera plugin request for apps media directory only. if we goto App info > permissions> Storage> Allow management of all files and enable the permission, this will work.
The final solution should be
either the plugin need to save the cropped file in the applications media directory or the application need to request for Allow management of all files permission.
thanks.