Hi everyone, I'm using this method by @Erel to take a picture from Android in my app released months ago.
Since some days, some customers told me that the "take picture" button is not working anymore, randomly.
After some investigation in my code, I could not find the problem... the only thing I noticed was that the notification that should appear from the "KeepRunningService" is not shown.
I tried starting from the original example code, excluding all my things in this way.
B4A + B4i project that uses an intent in B4A and the Camera object in B4i to take a picture using the default camera app. The B4A code depends on JpegUtils: https://www.b4x.com/android/forum/threads/11629/#content It rotates the bitmap based on the EXIF orientation attribute. Don't miss: -...
www.b4x.com
And i manged to replicate at least one scenario that can cause the problem, it proves that there is some sort of problem.
Open the App
Click on the only button to take a picture (but the notification still not shown even with the original code, I remember in the past that it was shown)
System camera opens
Take a picture
Confirm
See the result in the ImageView
You can repeat this procedure as many times you want, it will work (based on my repeated tests)
After confirming that with this flow it works correctly, proceed by doing the following in order to TRIGGER THE BUG:
Put a breakpoint on line 58 Wait For ion_Event (MethodName As String, Args() As Object)
Execute one more time the WORKING PROCEDURE explained above
The code will be blocked on the breakpoint, simply go on (it will work)
TRY AGAIN TO TAKE A PICTURE
At this point it will no longer work... and there is more, the Button_Click sub is not trigger anymore... is like the button is not liked with its event anymore...
At minute 0:13 the long pause is because I'm setting the breakpoint
I found that putting a sleep between the StartActivityForResult and the Wait For ion_Event it does not freeze anymore, and the camera opens again...
(Note: I tried putting the sleep directly inside StartActivityForResult, but in this way does not work)
But I don't know what is going on, so I don't know if this is just a coincidence, I don't know if it can happen again in some other circumstances.
B4X:
StartActivityForResult(i)
Sleep(10)
Wait For ion_Event (MethodName As String, Args() As Object)
No, in fact the breakpoint is the only way I found to reproduce it in a wanted manner, but this problem happens in production on clients phones.
It randomly happens, it is impossible to reproduce in other ways.
I confirm that the problem exists because it happened in first person too, just one time, while I was trying to trigger it (without breakpoints, it was in release mode):
I took 1 picture (this number is also random), then stop... impossible to take other pictures... the button still shows its animation when clicked (it was not disabled), it's like if when this happens the button (event) that started the intent lose his linking with the callback somehow. The exact same behavior that you can reproduce with the breakpoint.
So... if the same exact problem exhibit in release, and then there is even a single way to reproduce it in a controlled manner, it means that some strange behavior exists.
When you put a breakpoint there, you are causing the event to be skipped because it is raised before the Wait For is called.
I understand that you encountered a real problem but I'm not convinced that it is related to this one. Try to reproduce it in release mode and monitor the logs.