-
Notifications
You must be signed in to change notification settings - Fork 598
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
Capacitor Camera restarts apps on certain Android 13 devices #1736
Comments
Can anyone from the Capacitor team at least let me know they've seen this report? My Android app is getting review bombed due to this bug |
Hey @klaurtar! There are two pieces you need to handle this in your application. When you go to open something over the top of your application, in this case camera, but it could apply to other things too, you should save enough information about the state of your application that you can restore it if the OS kills your application. That might include things like what page the user was on, any form data, etc. This would allow you to restore your app state on init again if needed. Then, whenever you return from this other "something" that you're doing, you would clear that data from memory, so you don't restore to this state later when it doesn't make sense. That's the first half. The second half is "how do I get the data from the camera if the webview was restarted?" Obviously, you'll have no more promise to await, however, the camera data will still be made available through the appRestoredResult. This is our way of providing your app with any data sent to your application if it had been closed due to the Android OS killing your app in the background (same as described in the SO link above). Put those two pieces together, and you can smoothly handle your app restarting due to Android low memory behavior! |
Thank you for the detailed reply. I will see if this helps. |
I had the same problem, my solution was to change CameraResultType.Uri to CameraResultType.Base64. But I need an effective solution that allows me to use CameraResultType.Uri. |
I am still getting this issue. Not only on Android but iOS as well. I added Crashlytics log around Here are the device details of an Android device restarting: Operating System |
@michael-arboleda Yeah that is my thoughts as well. The phones have plenty of memory left when this happens. I have started working on adding the fix the Capacitor team recommended above. It is a bit of a hacky workaround having to access the pre-crash state and then get the user back to where they were. Were you able to recreate the issue on the sample application I provided? |
@dallastjames Anyway to get a second look at this? @michael-arboleda brings up a good point with his above comment. I still think Capacitor could have a bug |
UPDATE: When the application is in the camera UI from calling the Camera.getPhoto method, the bug almost NEVER occurs when the flash is turned on. |
@klaurtar I'm happy to look at this issue again, but I do still believe that this is most likely the Android OS just killing the app in the background. We've looked at the sample provided and tested across our devices and have not been able to replicate this issue, so at the moment, there really isn't anything we can do about without additional information. If the application is crashing, there should be crash logs from that, and I believe you can typically get those from your play store console to help debug crashes in production. Any chance you could provide those here? The most likely case here is just the Android OS killing your app in the background. According to the Android Activity lifecycle docs the state of having the camera in the foreground puts your application in the Anyways, if you do have crash logs I'd love to see them and we can take a look to see if there's something telling within the logs that can help us track down if there is a bug in Capacitor. If there is, we'll happily take a look and see what we can do! |
One other resource one of the other team members brought up. It hasn't been updated super recently, but we haven't seen anything indicating that anything has changed since Android 11 anyways. https://dontkillmyapp.com/samsung Samsung is notoriously quick to kill background apps, so it's not surprising that all the reported devices here as Samsung devices as well. |
@dallastjames Thanks for the update. I've implemented the above fix you mentioned and it's working. I'll continue to do some digging and see if I can gain any insights on the issue, and report back. I'm glad Capacitor has an answer for this out of the box. Thank you! |
I have a very lowend Android and as time goes by, it kills more and more apps while taking pictures. It's not a good solution, but it might help to lower the overall quality from the camera settings (at least for testing purposes) |
i also get the similer problem while i am taking image using camera.getPhoto it's take the image but i submit the click or just click on right button it's crash my app and restart the application |
I'm having this exact same issue with some high-end devices! |
I also received two bug reports from separate clients using our app running Capacitor. |
I'm looking for the solution |
@dallastjames Thank you for the ton of details you've provided about this! Do you know of any way to simulate this situation? To effectively force Android to close the app while the camera is open, so I can test the fixes to it? |
In developer settings on your android phone you want to turn on the setting "Don't Keep Activities" |
@dallastjames hello, I'm having this exact same |
I think @capcitor/camera should migrate to Camera X to solve this problem. Any contributors here who can do this? |
@klaurtar was the suggested fix you implemented to store and restore the app state if it crashes? |
-> No appRestoredResult is produced as far as I can tell. Am I missing something? Do I have to modify AndroidManifest or MainActivity in any way? thanks in advance |
Apparently I had and old version of MainActivity.java (I mean, generated by an old capacitor version), so after I removed the following "outState.clear();", it worked as expected:
|
Hello, We are observing the same issue with a device in particular : It is running on Android 14. We call the function like this: Camera.getPhoto({ If it may help, we observed that the issue occurs more frequently when the "Automatic HDR" option is enabled in the settings when taking a photo. It probably always occurs when HDR mode is effectively applied. But it sometimes occurs even when Automatic HDR is disabled. We tried to reproduce it with the same application on other devices (Samsung galaxy S24 for example with Android 14 as well, and on older devices), but without success. When analyzing in debug with android studio, we don't see a memory peak, it's just as if the webview was restarted. Let us know if we can help to solve this issue. |
a client of mine is reporting this exact issue with this exact phone, running Android 13.0.3 I've tried reducing the image quality (100 to 50) and disabling image editing but he is still reporting the same issue. I can try the state restore solution but it seems like that would take a bit of work. any other possible solutions that would be quick to try? |
@dallastjames I think these logs/findings will help confirm your thoughts here. I've been seeing this issue on a Samsung S7 FE SM-T733. On the device it shows I have 1.1 GB of ram available out of 4. If I set the battery optimization for my app to unrestricted it seems to help but did not fully stop the issue from occurring. If I set it to restricted, that seems to make the problem more apparent as expected. I'm not sure why this occurs on some devices and not others. They must have different settings. We have older devices running Android 13/14 with the same or less ram and they work fine. I believe it is the lmkd driver that is causing this. See logs below. Notice
|
Bug Report
Plugin(s)
@capacitor/camera v5.X.X
Capacitor Version
Platform(s)
Certain Android devices running Android 13 with SDK version 33
Reports of this happening have come from:
Current Behavior
When Camera.getPhoto() is called the system allows the user to choose a photo or take a photo. When take a photo is clicked, the system's camera UI is displayed. A user is then allowed to take a photo. When the photo is taken, it will then ask the user if they would like to retry the photo or if it is ok. When the ok option is selected, the app restarts as if the user had just opened the app. No debugging occurs as the console is wiped everytime this happens.
Screen_Recording_20230814_223820_bad_camera_android.mp4
Expected Behavior
Camera.getPhoto() should allow Android 13 users to take a photo, and then approve the photo. This should not restart the app.
Record_2023-08-14-22-40-15.mp4
Code Reproduction
Here is a working recreation of the bug
Run the Android app on a physical Samsung Android 13 device like I listed above. Click the + icon on the placeholder image to take a photo. Then quickly click the ok or checkmark button. This should cause the app to restart. I had to take a photo 3 times before the bug started occurring. If it is not occuring, kill the app and restart it and repeat the process.
Other Technical Details
Additional Context
I found this related Ionic forum post about this issue
I also noticed from testing that if a user with an effected device takes a photo, then waits for about 10 seconds before pressing ok or the checkmark on the system UI, it will work as it should. However, if a user quickly takes a photo and accepts it, the app restarts.
I unfortunately need a fix for this asap. My business relies on this feature. Thanks!
The text was updated successfully, but these errors were encountered: