Android Question Catching events for folding devices

CaptKronos

Active Member
Licensed User
Longtime User
I submitted an app to the Samsung App Store and whilst it was accepted I received a message about it not being compatible with folding devices i.e. it did not update its display when a folding device changed its state (folded to unfolded, unfolded to folded). I have not played around with such devices before and don't have one, but have been having fun with Samsung's Remote Test Lab https://developer.samsung.com/remote-test-lab. I have discovered that B4A does not seem to expose the folding device events. Am I missing something, or has anyone implemented this functionality? I have started to do the latter myself, but the path I have been taking is getting complicated. I'm trying to follow this (Microsoft!) information: https://learn.microsoft.com/en-us/dual-screen/android/jetpack/window-manager.
 

CaptKronos

Active Member
Licensed User
Longtime User
I thought I had found a solution, which was to use the phone's sensors. Scanning for all the sensors on the Galaxy Z Fold 5 and the Fold 4 (using Samsung's Remote Test Lab), I identified a series of promising looking sensors:

B4X:
    Public const SENSOR_TYPE_HINGE_ANGLE As Int=36
    Public const SENSOR_TYPE_FOLDING_ANGLE_NON_WAKEUP As Int=65686
    Public const SENSOR_TYPE_lid_angle_fusion_Wakeup As Int=65695
    Public const SENSOR_TYPE_folding_state_lpm_Wakeup As Int=65697
So I started monitoring them and folded/unfolded the phone.
B4X:
    PSHinge1.Initialize(SENSOR_TYPE_HINGE_ANGLE)
    PSHinge1.StartListening("SENSOR_TYPE_HINGE_ANGLE")
    PSHinge2.Initialize(SENSOR_TYPE_FOLDING_ANGLE_NON_WAKEUP)
    PSHinge2.StartListening("SENSOR_TYPE_FOLDING_ANGLE_NON_WAKEUP")
    PSHinge3.Initialize(SENSOR_TYPE_lid_angle_fusion_Wakeup)
    PSHinge3.StartListening("SENSOR_TYPE_lid_angle_fusion_Wakeup")
    PSHinge4.Initialize(SENSOR_TYPE_folding_state_lpm_Wakeup)
    PSHinge4.StartListening("SENSOR_TYPE_folding_state_lpm_Wakeup")
The only sensor that fired was SENSOR_TYPE_HINGE_ANGLE and that was only on folding the phone. (It didn't fire on unfolding!)
Interestingly, the Fold 4 paused and resumed the B4A activity whenever the phone was folded and unfolded. This would be an ideal time to check to see if the screen size had changed, but the Fold 5 did not have this behaviour, the Fold 5 only paused and resumed the activity on folding. So that approach doesn't seem to be viable.
 
Upvote 0

CaptKronos

Active Member
Licensed User
Longtime User
I have now tried doing this with the Android Emulator, and it would seem that SENSOR_TYPE_HINGE_ANGLE works as you would expect. Angles are continually generated as the screen is folded and unfolded. Perhaps Samsung's Remote Test Lab doesn't convey sensor information correctly? Or perhaps the emulator isn't behaving like a real device? I would be interested in someone with a real device testing to see if this sensor fires reliably. Thanks.
 
Upvote 0

CaptKronos

Active Member
Licensed User
Longtime User
Thanks for the link, Wes. That page seems to immediately answer my query: "You need to store the position or ID of the photo, as Android destroys and recreate the activity when folding and unfolding the phone." I had assumed the activity would need to be recreated (and hence we could utilise those events) but some of the devices on Samsung's Remote Test Lab didn't behave in that way. It must be just the way the Remote Test Lab has been set up.
If you have the time, perhaps you could just run any of your apps or just create a new default app on your Flip and check that the log is recording the Activity resume and pause events when you open and close your phone:

** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **

Thanks.
 
Upvote 0
Top