apache / cordova-plugin-camera

Apache Cordova Plugin camera
https://cordova.apache.org/
Apache License 2.0
966 stars 1.55k forks source link

Cordova-plugin-camera crashes app on android devices #660

Closed lanadedstudio closed 3 weeks ago

lanadedstudio commented 4 years ago

Issue Type

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

charlieshin commented 4 years ago

I have same problem here for version 4.2.

erisu commented 4 years ago

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

olidotjpeg commented 4 years ago

I am having a similar issue where when I take a picture with the new version 5.0.0 on Cordova 10 it just returns a null

timbru31 commented 4 years ago

Is this reproducible in a new, plain Cordova app? A minimal reproduction repository would really help to debug and later fix this issue. More information on how to create one: https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md

olidotjpeg commented 4 years ago

Just checked with a fresh cordova app, also fails there. If I have editing enabled, it says editing isn't allowed, and if I disable it it just sends out a Error capturing image. in the console.

breautek commented 4 years ago

Can you test with FILE_URI instead of DATA_URL destination types?

In my experience, DATA_URL can cause memory issues and results in crashes on some devices, because representing high resolution images in a bae64 encoded string is rather inefficient. This is also noted in the docs.

Alternatively, you could also try resizing the image using the targetWidth and targetHeight camera options.

I am having a similar issue where when I take a picture with the new version 5.0.0 on Cordova 10 it just returns a null ... Just checked with a fresh cordova app, also fails there. If I have editing enabled, it says editing isn't allowed, and if I disable it it just sends out a Error capturing image. in the console.

I'm not convinced this is the same issue as the OP described. You're describing an error case, where the OP is describing a crash (which I may be falsely interpreting that the app is closing unexpectedly). You may want to create a new issue so that we can track the issue you described independently.

lanadedstudio commented 4 years ago

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

I will test with the new version! TKS

I'm using the android version 8.1.0 because i'm building my app with Monaca and them requires this version... but i will try update android too

olidotjpeg commented 4 years ago

@breautek We are already using FILE_URI. I will create a new repo to track these issues differently

Moved my issue discussion over to as that is the right issue as it's the exact same as me. https://github.com/apache/cordova-plugin-camera/issues/611

PieterVanPoyer commented 3 years ago

@lanadedstudio is this issue still happening with the latest released version? If not, feel free to close this issue.

lanadedstudio commented 3 years ago

Yes, this continues to happen on some devices. Even with the updated plugin and using FILE_URI instead of DATA_URL.

PieterVanPoyer commented 3 years ago

Are you able to provide a stacktrace of the crashes?

lanadedstudio commented 3 years ago

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.

PieterVanPoyer commented 3 years ago

Image editing is really discouraged in this plugin. image

rfernandoinfocast commented 3 years ago

hey guys: I was using version 4.2.0 and it was working well. Now I'm trying to install this version again and I'm not been able. What did happen to version 4.2.0 ?

breautek commented 3 years ago

hey guys: I was using version 4.2.0 and it was working well. Now I'm trying to install this version again and I'm not been able. What did happen to version 4.2.0 ?

Version 4.2.0 was never released because it contained https://github.com/apache/cordova-plugin-camera/pull/588 which broke some things on Android.

https://lists.apache.org/thread.html/rd4e20db0cc4e038f3ea9c14d29648fded38f7605359253c976a2e38d%40%3Cdev.cordova.apache.org%3E

rfernandoinfocast commented 3 years ago

hey guys: I was using version 4.2.0 and it was working well. Now I'm trying to install this version again and I'm not been able. What did happen to version 4.2.0 ?

Version 4.2.0 was never released because it contained #588 which broke some things on Android.

https://lists.apache.org/thread.html/rd4e20db0cc4e038f3ea9c14d29648fded38f7605359253c976a2e38d%40%3Cdev.cordova.apache.org%3E

ok! thanks a lot.

delvinwidjaja commented 3 years ago

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

PieterVanPoyer commented 3 years ago

Are you able to provide a stacktrace of the crashes?

delvinwidjaja commented 3 years ago

@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

breautek commented 3 years ago

@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.
delvinwidjaja commented 3 years ago

@breautek thank you for your help. now it works as expected

PieterVanPoyer commented 3 years ago

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

lanadedstudio commented 3 years ago

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.

21pg commented 3 years ago

@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 fix(android): supports sdk-30 package visibility #684 This solution should work for both API 29 and API 30.

will this work with cordova-android 10.0.0 As due to https://github.com/apache/cordova-android/issues/1250 I removed all edit-config and config-file tags from my config.xml

breautek commented 3 years ago

will this work with cordova-android 10.0.0

The PR mentioned in my comment has been merged. You can give it a test by installing this plugin from github. cordova-android@10 is required as it contains breaking changes making it incompatible with cordova-android@9.

Quentin-Laplace commented 2 years ago

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.

luizcantoni commented 2 years ago

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.

sithwarrior commented 1 year ago

Im still seeing some instances of this error on Android devices, even with the latest release of this plugin and Cordova-android

android.app.RecoverableSecurityException$1.createFromParcel

Exception java.lang.RuntimeException:
  at android.app.ActivityThread.deliverResults (ActivityThread.java:5994)
  at android.app.ActivityThread.handleSendResult (ActivityThread.java:6033)
  at android.app.servertransaction.ActivityResultItem.execute (ActivityResultItem.java:67)
  at android.app.servertransaction.ActivityTransactionItem.execute (ActivityTransactionItem.java:45)
  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:2574)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8762)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:604)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)
Caused by android.app.RecoverableSecurityException:
  at android.app.RecoverableSecurityException$1.createFromParcel (RecoverableSecurityException.java:197)
  at android.app.RecoverableSecurityException$1.createFromParcel (RecoverableSecurityException.java:194)
  at android.os.Parcel.readParcelableInternal (Parcel.java:4787)
  at android.os.Parcel.readParcelable (Parcel.java:4755)
  at android.os.Parcel.createExceptionOrNull (Parcel.java:3018)
  at android.os.Parcel.createException (Parcel.java:3007)
  at android.os.Parcel.readException (Parcel.java:2990)
  at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:190)
  at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:142)
  at android.content.ContentProviderProxy.delete (ContentProviderNative.java:629)
  at android.content.ContentResolver.delete (ContentResolver.java:2340)
  at android.content.ContentResolver.delete (ContentResolver.java:2306)
  at org.apache.cordova.camera.CameraLauncher.checkForDuplicateImage (CameraLauncher.java:1277)
  at org.apache.cordova.camera.CameraLauncher.cleanup (CameraLauncher.java:1242)
  at org.apache.cordova.camera.CameraLauncher.processResultFromCamera (CameraLauncher.java:626)
  at org.apache.cordova.camera.CameraLauncher.onActivityResult (CameraLauncher.java:877)
  at org.apache.cordova.CordovaInterfaceImpl.onActivityResult (CordovaInterfaceImpl.java:160)
  at org.apache.cordova.CordovaActivity.onActivityResult (CordovaActivity.java:375)
  at android.app.Activity.dispatchActivityResult (Activity.java:8951)
  at android.app.ActivityThread.deliverResults (ActivityThread.java:5987)

according to the Google Play Console, its happening on different devices on Android 13