Android Question Intent based camera problem

doncx

Active Member
Licensed User
Longtime User
I have implemented a version of the intent-based camera example in a larger cross-platform B4XPages app. It works beautifully, except on some Android phones it crashes. Only some. I've also encountered one device (Samsung Galaxy S23) that exhibited the problem but then - for no known reason - was alright. The symptom is that the camera is activated, the photo taken, but when "OK" is tapped, some minority of Android devices restart the app. iOS is solid, though my uploaded example is Android-only.

I've reworked Erel's originally-posted code to exist in a class (CameraClass) because it is called from several locations in the app.

I'm uploading an example here of several pages that duplicate the navigation model of my app. It is android only, and crashes on the same devices. I can't figure out if it's environmental or what is causing the problem. If you look at the logs, when it fails the app is simply restarted instead of returning from the camera with the image.

Remember, it usually works just fine. Just some devices...

Could someone have a look and see what you think?

Many Thanks!

Log of successful camera use:
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
*** start: B4XPage_Created
*** addphoto: B4XPage_Created
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** mainpage: B4XPage_Disappear [mainpage]
*** start: B4XPage_Appear [mainpage]
*** start: B4XPage_Disappear [mainpage, start]
*** addphoto: B4XPage_Appear [mainpage, start]
Using FileProvider? true
entering TakePicture
Calling StartActivityForResult
Completed StartActivityForResult
** Activity (main) Pause event (activity is not paused). **
*** addphoto: B4XPage_Disappear [mainpage, start, addphoto]
AddPhoto Page Disappearing
sending message to waiting queue (OnActivityResult)    <--- Ahh.  This is what is supposed to happen
running waiting messages (1)
Waited for ion_Event
Orientation: 6
about to call image_available
** Activity (main) Resume **
*** addphoto: B4XPage_Appear [mainpage, start, addphoto]

Log of FAILED camera use:
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
*** start: B4XPage_Created
*** addphoto: B4XPage_Created
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** mainpage: B4XPage_Disappear [mainpage]
*** start: B4XPage_Appear [mainpage]
*** start: B4XPage_Disappear [mainpage, start]
*** addphoto: B4XPage_Appear [mainpage, start]
Using FileProvider? true
entering TakePicture
Calling StartActivityForResult
Completed StartActivityForResult
** Activity (main) Pause event (activity is not paused). **
*** addphoto: B4XPage_Disappear [mainpage, start, addphoto]
AddPhoto Page Disappearing
*** Service (starter) Create ***     <---- WHOA! The app just restarted!
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
*** start: B4XPage_Created
*** addphoto: B4XPage_Created
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
 

Attachments

  • FlakyCamera.zip
    16.9 KB · Views: 116

Alessandro71

Well-Known Member
Licensed User
Longtime User
I don't know if it applies here, but I found the same issue on another Samsung model.
It happens when you rotate the phone while taking the picture and return back to the app in an orientation mode that is different from the one you started with.
No solution as of today, though...
 
Upvote 0

zed

Active Member
Licensed User
Test on
Huawei - Android 5.5
Samsung - Android 10
Xiaomi = Android 12
No problems encountered
 
Upvote 0

doncx

Active Member
Licensed User
Longtime User
Thank you, Erel! This seems to fix my problem. Your assessment of the issue is dead-on and makes perfect sense. I only wish I'd thought of it myself. I've tested it on a device that consistently failed, and it works. Your updated example is also greatly appreciated. It's a fantastic cross-platform solution. THANK YOU
 
Upvote 0

doncx

Active Member
Licensed User
Longtime User
I have noticed an problem behavior that seems related to Erel's solution. At first I thought it an anomaly but it appears to be a frequent behavior: The first time the "Take Picture" button is clicked, nothing happens - the camera function is called but it bounces right back out. The second time it's clicked, a toast message "Camera is not available appears" but the camera also appeasrs. However, when the photo is taken and "OK" clicked, nothing returns to the caller. Subsequent photos are taken successfully.

I'm thinking that the "KeepRunning" service is not getting started in time, but to be honest I'm a bit confused.

I've uploaded my class-oriented version again here, with Erel's improvements. Does someone have a suggestion of how to deal with this? I've not figured it out.

Thank you
 

Attachments

  • FlakyCamera.zip
    17.6 KB · Views: 117
Upvote 0

doncx

Active Member
Licensed User
Longtime User
Your example works well.

I seem to have fixed my issue by starting the KeepRunning service upon app start (B4XMainPage_Created) instead of when initializing the CameraClass. Then, the "Start" and "Stop" calls are implemented in the CameraClass as you exhibited in your example. This does seem to indicate that the problem was indeed that the KeepRunning service was not starting quickly enough in the class.

Thanks for your continued assistance.
 
Upvote 0
Top