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

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

Open
3 tasks done
Lerolben opened this issue Sep 29, 2023 · 11 comments
Open
3 tasks done

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

Lerolben opened this issue Sep 29, 2023 · 11 comments

Comments

@Lerolben
Copy link

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

  • The problem only appears on my moto g42 (android 12)
  • I made sure that the camera on the phone works separately
  • Everything works fine on my other phones:
    -- 2 other phones with android 12 (Samsung s10, Oppo A54 5g)
    -- Some other phones with android: 9, 10, 11, 13

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

  • Android
  • Api target 33
  • cordova-plugin-camera: 7.0.0
  • Ionic 7.1.0

Checklist

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

This comment was marked as off-topic.

@viking2917
Copy link

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
Copy link

Following the thread here: #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
Copy link
Author

Lerolben commented Oct 8, 2023

@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
Copy link

viking2917 commented Oct 8, 2023 via email

@rideo-eduardmorales
Copy link

rideo-eduardmorales commented Oct 26, 2023

@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
Copy link

rideo-eduardmorales commented Oct 26, 2023

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
Copy link
Author

@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
Copy link

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
Copy link

ZaKull commented Feb 15, 2024

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.

@breautek
Copy link
Contributor

If the activity gets killed during getPicture call (while the camera application is open), it's callback won't get called.

When the activity gets reloaded it requires reconstructing the webview, which means your web app will also be re-loaded. The JS state is not restored.

The response will be available inside the resume event however.

This is likely the case. You can forcefully test this case by enabling developer options on the android device and then enable the Don't Keep Activities option in the Developer settings. With this enabled, the OS will always kill the activity when the Camera intent starts, allowing you to test the that quirk. It's part of normal android behaviour, so it's something that developers are expected to handle.

This bug report sounds like this is the situation. @Lerolben were you able to confirm this?

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

No branches or pull requests

7 participants