Android Question How do you detect "flex mode" for z fold 3

Robert Durbin

New Member
Licensed User
Longtime User
Is there is a way to detect flex mode on Samsung z fold devices using B4A? Flex mode allows you to place main content (like video) on upper portion of screen and controls on lower portion when device is folded at a certain angle or greater. I did find this but unsure how to make use of it on B4A
 

agraham

Expert
Licensed User
Longtime User
On my Surface Duo, and probably your Flex, there is a hinge sensor that you can access. The type number of the hinge sensor on the Duo is 33171006 but is probably different on your Samsung. You can get a list of the sensors on your phone and do a case-insensitive search for a sensor name including "hinge" to get the type number which you can then pass to a Phone library PhoneSensor.Initialize method.

To determine if you are spanned or not you will probably need to look at the Activity size as the Jetpack Windows Manager API which formalizes such things is in Android 11 and is effectively in beta so I haven't played with it yet as my Duo is on Android 10 and the folding APIs, few as they are, are presently Microsoft Duo specific so I'm waiting for the expected upgrade to Android 11 before I do any serious investigation.

B4X:
''@N:GetSensors As returnvalue
''Return a string containing details of all the sensor types available to the program.
''Within the string the details for each sensor are enclosed by braces, {},  and terminated by a CRLF character.
''Within the braces are values for the sensor: Sensor name, vendor, version, type, maxRange, resolution, power and minDelay.
''These values are presented as comma separated declarations of the form: Sensor name="Some sensor", ...,type=1,...
''Type is the integer value of the Sensor constant used to identify the sensor when invoking AddSensor.
Sub GetSensors As String
    Dim NativeMe As JavaObject
    NativeMe.InitializeContext
    Dim returnlist As List
    returnlist = NativeMe.RunMethod("getSensorList",Null)
    Dim sensors As String = ""
    For i = 0 To returnlist.Size - 1
        sensors = sensors & returnlist.Get(i) & CRLF
    Next
    Return sensors.SubString2(0, sensors.Length - 1)
End Sub

#If Java
import java.util.List;
import android.hardware.Sensor;
import android.hardware.SensorManager;
SensorManager sMgr;
public List getSensorList() {
    sMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
    List<Sensor> list = sMgr.getSensorList(Sensor.TYPE_ALL);              
    return list;
}  
#End If
 
Last edited:
Upvote 0
Top