apache / cordova-plugin-camera

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

Android 12, moto g42 getPicture not response, no error #859

Open Lerolben opened 7 months ago

Lerolben commented 7 months ago

Bug Report

Problem

On android 12 (moto g42) getPicture method do nothing. Nothing happens. Nothing shows up. The method returns neither an error nor a success. The phone doesn't freeze. Just tap on my button and nothing happens. The promise is not fulfilled.

LogCat shows only this:

To native (Cordova plugin): callbackId: Camera936725130, service: Camera, action: takePicture, actionArgs: [90,0,1,-1,400,0,0,false,true,false,null,0]

I have 2 other phones with android 12, and some phones with androids 9, 10, 11, 13 and everything works fine on them on the same app. I tried repeatedly to install the application, clear data, etc.

What is expected to happen?

The camera should open

What does actually happen?

Nothing

Information

Command or Code

const options: CameraOptions = {
            quality: 90,
            allowEdit: false,
            destinationType: this.camera.DestinationType.FILE_URI,
            encodingType: this.camera.EncodingType.JPEG,
            sourceType: pictureSourceType,
            mediaType: this.camera.MediaType.PICTURE,
            correctOrientation: true,
        };
this.camera.getPicture(options).then((imageData) => {
  // the code does not execute here
...
, (err) => {
  //  the code here also doesn't execute          
 }

Environment, Platform, Device

Checklist

ivanprojetosti commented 7 months ago

Hello i'm with the problem "No image Selected" after update the cordova for 12.0.1 e cordova-plugin-camera: 7.0.0 and my camera sometimes dont works. Did you have this problem ?

viking2917 commented 7 months ago

I have users reporting the same or similar issue on a Galaxy S23. I am unable to reproduce the problem myself on an older galaxy

viking2917 commented 7 months ago

Following the thread here: https://github.com/apache/cordova-plugin-camera/issues/826, I installed this fork: https://github.com/jalios/cordova-plugin-camera/

And my problem was solved. The problem appears to be related to new permission requirements on the latest Android, so older versions do not have the problem.

(v7 of the standard apache/cordova-plugin-camera apparently also fixes the problem, but I was unable to use it because I am fixing a very old app on ionic v1 which is pinned to android 10, which is too old for this plugin, but the jalios plugin was able to work for me.)

Lerolben commented 7 months ago

@viking2917 I have the latest version of the plugin, which works well on many of my phones running all versions of Android (8, 9, 10, 11, 12, 13). The problem only appears on Motorola G42 with Android 12. I don't know if it's a problem with this specific phone or Motorola G42 in general. Please let me know if any of you have a G42 with Android 12 and this plugin works for you.

viking2917 commented 7 months ago

Sorry I do not have a that device :(

On Sat, Oct 7, 2023 at 9:23 PM Lerolben @.***> wrote:

@viking2917 https://github.com/viking2917 I have the latest version of the plugin, which works well on many of my phones running all versions of Android (8, 9, 10, 11, 12, 13). The problem only appears on Motorola G42 with Android 12. I don't know if it's a problem with this specific phone or Motorola G42 in general. Please let me know if any of you have a G42 with Android 12 and this plugin works for you.

— Reply to this email directly, view it on GitHub https://github.com/apache/cordova-plugin-camera/issues/859#issuecomment-1751946706, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2VYVJKQN35FMSZBZPM6XDX6JIGJAVCNFSM6AAAAAA5MPHDTOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJRHE2DMNZQGY . You are receiving this because you were mentioned.Message ID: @.***>

rideo-eduardmorales commented 6 months ago

@Lerolben We are having the same problem using the latest version of the plugin. Any news on your side?

The device is a Motorola g51 5G in our case. When the device was with Android 11, the pictures were captured without problems, but after the device was updated to Android 12, it works only sometimes. From 10 attempts, only 2 finished successfully.

What happens is that after pressing the camera icon (to open camera), most of the time the app shows a white screen and fully reloads the app, so the app home screen is shown. No useful logs are shown in logcat.

We have set the CameraOptions quality setting to 70 to try to minimize memory usage, but it doesn't seam to be this problem since the device has enough memory, and older devices, with far less memory, are working OK.

We're also using the latest versions ATM of these plugins: "cordova-plugin-camera": "7.0.0", "cordova-plugin-file": "8.0.0", "cordova-plugin-media": "7.0.0",

These are the devices/emulators we have verified the app is working OK: Samsung J5 (Android 9.0) Xiaomi Redmi 10 (Android 11) Samsung A13 (Android 13) Samsung XCover 5 (Android 13) Emulator (Android 12) Emulator (Android 12L)

Sadly, we don't have another Android 12 device to try at the moment…

rideo-eduardmorales commented 6 months ago

We found this:

The Android OS may kill activities that are in the background to preserve memory, particularly if the foreground activity requires a lot of memory. When you use the Camera App, it puts your app into the background.

This is documented here:

Android uses intents to launch the camera activity on the device to capture images, and on phones with low memory, the Cordova activity may be killed. In this scenario, the result from the plugin call will be delivered via the resume event. See the Android Lifecycle guide for more information. The pendingResult.result value will contain the value that would be passed to the callbacks (either the URI/URL or an error message). Check the pendingResult.pluginStatus to determine whether or not the call was successful.

We're not sure if maybe that pendingResult.result is what we need to handle to recover the picture data…

source

Lerolben commented 6 months ago

@rideo-eduardmorales Unfortunately, I still haven't found a solution to the problem. In my case the application does not restart. The plugin simply doesn't give any feedback. Maybe plugin developers should check pendingResult.result and what you wrote.

YanouonaY commented 3 months ago

Hello, for me the 'same' probleme with motorola g51. My app crash from plugin after capture picture and restart. Anyone have the same probleme?

Beside I have an user experience on motorola g9, the app crash with plugin camera and the phone doesn't restart. He has to plug the phone into power outlet. Anyone have the same probleme?

ZaKull commented 2 months ago

using background plugin.

The error occurs when you have to exit the app to take a photo and then when you return. I recommend using the background plugin so that when you go to take a photo, you put the app in background mode and when you return, you remove it.