Skip to content
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

Unable to create bitmap! #642

Open
3 tasks done
epetre opened this issue Aug 5, 2020 · 12 comments
Open
3 tasks done

Unable to create bitmap! #642

epetre opened this issue Aug 5, 2020 · 12 comments

Comments

@epetre
Copy link

epetre commented Aug 5, 2020

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 (cordova-lib@9.0.1)
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

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@PTRFRLL
Copy link

PTRFRLL commented Sep 10, 2020

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)

@wongpeiyi
Copy link

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

@furkankatman
Copy link

I am still seeing this issue. Any solution for this ?

@xuyonghua
Copy link

xuyonghua commented May 6, 2021

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);
}

`

@PieterVanPoyer
Copy link
Contributor

@epetre is this issue still happening with the latest version?

@shahdeep1989
Copy link

@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
};

@nileshbandekar
Copy link

@xuyonghua Perfect solution ,
Thank You...!!!!!!

@Xdabier
Copy link

Xdabier commented Feb 7, 2022

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>,

@fullmooooon
Copy link

fullmooooon commented Mar 3, 2022

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

@xiandanchaorenguagua
Copy link

resolved,thx~~

@kapilSoni101
Copy link

kapilSoni101 commented Mar 24, 2023

@xuyonghua sir can you tell me where we put above code?

@rashnk
Copy link

rashnk commented Aug 2, 2023

I am getting the same issue "unable to create bitmap"
device : realme 5 pro Android 11
Cordova : cordova-android 12

image
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests