Android Code Snippet Get Activity Orientation

B4X:
Sub Button1_Click   
    'check javaobject library
    Dim jo As JavaObject
    jo.InitializeContext
    Label1.Text=jo.RunMethod("getDeviceOrientation",Array As Object(jo.InitializeContext))
    ' 0 = portrait
    ' 1 = landscape left
    ' 2 = portrait reverse
    ' 3 = landscape right
End Sub

#if java
    
    import android.content.Context;
    import android.view.WindowManager;

    public static int getDeviceOrientation(Context context) {
            WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            int rotation = windowManager.getDefaultDisplay().getRotation();
            return rotation;
    }

#End If
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…