iOS Question Check screenorientation (left, top, right)

schimanski

Well-Known Member
Licensed User
Longtime User
I there something in B4i as the following code in B4A to check the screenorientation?
I know, that Page_Resize(Width As Int, Height As Int) gives the orientation, but I need to know, if the device is in right or left landscape.
In landscape, the heading of the device has always an 90° offset:
B4X:
Private Sub LocManager_HeadingChanged (MagneticHeading As Double, TrueHeading As Double)


B4X:
'B4A-Code:
Sub GetOrientation As Int
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod2("getSystemService", "window", "java.lang.String")
   r.Target = r.RunMethod("getDefaultDisplay")
   Return r.RunMethod("getOrientation")
End Sub

thanks for help...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub DeviceOrientation As String
   Dim no As NativeObject
   Dim o As Int = no.Initialize("UIDevice").RunMethod("currentDevice", Null).RunMethod("orientation", Null).AsNumber
   Select o
     Case 0
       Return "Unknown"
     Case 1
       Return "Portrait"
     Case 2
       Return "PortraitUpsideDown"
     Case 3
       Return "LandscapeLeft"
     Case 4
       Return "LandscapeRight"
     Case 5
       Return "FaceUp"
     Case 6
       Return "FaceDown"
   End Select
   Return "Unknown"
End Sub
 
Upvote 0
Top