cordova-plugin-camera: Cordova-plugin-camera crashes app on android devices

Issue Type

  • Bug Report
  • Feature Request
  • Support Question

Description

The app crashes when the photo is captured. Error checked on Android 9 and 10, on IOS works well

Information

Command or Code

    navigator.camera.getPicture(this.onSuccess, this.onFail, {
        quality: 50,
        allowEdit: false,
        correctOrientation: true,
        allowEdit: true,
        destinationType: destinationType.DATA_URL
    });

Environment, Platform, Device

Version information

Cordova Packages:

cli: 10.0.0
    common: 4.0.2
    create: 3.0.0
    lib: 10.0.0
        common: 4.0.2
        fetch: 3.0.0
        serve: 4.0.0

Project Installed Platforms:

android: 8.1.0
ios: 6.1.1

Project Installed Plugins:

cordova-plugin-actionsheet: 2.3.3
cordova-plugin-add-swift-support: 2.0.2
cordova-plugin-biometric: 0.0.3
cordova-plugin-camera: 4.0.3
cordova-plugin-dialogs: 2.0.2
cordova-plugin-file-transfer: 1.7.1
cordova-plugin-file: 6.0.2
cordova-plugin-fingerprint-aio: 3.0.1
cordova-plugin-geolocation: 4.0.2
cordova-plugin-keyboard: 1.2.0
cordova-plugin-network-information: 2.0.2
cordova-plugin-whitelist: 1.3.4

Checklist

  • I searched for already existing GitHub issues about this
  • I updated all Cordova tooling to their most recent version
  • I included all the necessary information above

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 2
  • Comments: 28 (11 by maintainers)

Most upvoted comments

@charlieshin @lanadedstudio can you both try with the latest camera plugin release?

I have just released a few hours ago version 5.0.0.

You should be able to use the latest just by removing and readding.

cordova plugin rm cordova-plugin-camera
cordova plugin add cordova-plugin-camera

Sorry, I should also note that the latest release also required Cordova-Android platform >= 9.0.0.

Yes, the problem persists

Cordova Version: 10.00 Cordova Plugin Camera Version: 5.0.1

I recently tested the error on smartphone models:

Smartphone Model: Moto G7 Play OS Version: Android 10

Smartphone Model: Asus_X00TDB OS Version: Android 9

When I installed an external camera app (not the android camera) it worked normally.

Hi, is there any update on this issue ? I’m using the plugin v5.0.1 and the app still crashes after taking a photo with the back camera

Device: Motorola E7 with 4 GB RAM Android: 10

My solution was install Open Camera and use this app to take photos from my Cordova App.

Before Open Camera I was using the Motorola’s Camera App that abruptly closes my app after I confirm a taken photo.

I confirm that upgrading to 6.0.0 along side updgrading to cordova 10 and cordova-android 10 works in our project.

Nb : If you upgrade cordova from 8 to 10, don’t forget to add cordova-plugin-androidx-adapter plugin in your project, and verify gradle dependencies, in our case com.google.gms:google-services needs to be updated to 4.3.8.

@lanadedstudio is this issue still occuring with the latest Cordova and Cordova plugins versions?

@PieterVanPoyer sorry for the late reply, this is what I got from the log

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=34, result=-1, data=null} to activity {de.myapp/de.myapp.MainActivity}: android.app.RecoverableSecurityException: de.myapp has no access to content://media/external/images/media/97
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4877)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4918)
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2045)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7399)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
Caused by: android.app.RecoverableSecurityException: de.myapp has no access to content://media/external/images/media/97

Btw I tested it with the front camera and it logged the same error.

Cordova-plugin-camera : v.5.0.1 cordova-android : 9.1.0 tested on Android 10 Devices

This plugin likely doesn’t handle API 29/30 changes to external storage. There should be potential two workarounds for the time being:

  1. Target API 29 and add requestLegacyExternalStorage flag to the AndroidManifest.xml file

Adding this to your config.xml should work:

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
    <application android:requestLegacyExternalStorage="true" />
</edit-config>

Note: requestLegacyExternalStorage is ignored on API 30.

  1. Fork this plugin and apply the PR https://github.com/apache/cordova-plugin-camera/pull/684 This solution should work for both API 29 and API 30.

After updating the plugin, the photos with the front camera are working, but the photos with the back camera still close the application. I removed the option to allow image editing. I also tested it with another camera app and it worked.