Android Question how determine device orientation when app starts

renzino

Member
Licensed User
Longtime User
Hello, when my app starts in portrait mode is displayed correctly, but if i put the device in landscape mode and launch the app, something get wrong, the splash screen is not displayed and some text in buttons are not setted, why? i forced orientation with "SetScreenOrientation(1)", but the problem remains....
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
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("getRotation")
End Sub
Uses REFLECTOR-Library
 
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
There's probably a lot wrong with my method but it seems to work.

B4X:
Sub GetOrientation As String

    Dim lv As LayoutValues 
    lv = GetDeviceLayoutValues
   
    If lv.Height > lv.Width Then
        Return "P"
    Else
        Return "L"
    End If
   
End Sub
 
Upvote 0

Federico956

Member
Licensed User
Longtime User
There's probably a lot wrong with my method but it seems to work.

B4X:
Sub GetOrientation As String

    Dim lv As LayoutValues
    lv = GetDeviceLayoutValues
 
    If lv.Height > lv.Width Then
        Return "P"
    Else
        Return "L"
    End If
 
End Sub

I think that this code is enough, but I'm note sure:
B4X:
If 100%y > 100%x Then
    Return "P"
Else
    Return "L"
End If

EDIT: I've tried it and it works!
 
Upvote 0
Top