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.
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