Android Question "WindowManager" and "Configuration" objects in B4A?

TheMightySwe

Active Member
Licensed User
Longtime User
Hi again,

new day, new problem. Is there anyway in B4A to read the "WindowManager" and "Configuration" objects as in this example in Java.

I need to find ot the natrual orientation for a device.


B4X:
Public Int getDeviceDefaultOrientation() {

    WindowManager windowManager =  (WindowManager) getSystemService(WINDOW_SERVICE);

    Configuration config = getResources().getConfiguration();

    Int Rotation = windowManager.getDefaultDisplay().getRotation();

    If ( ((Rotation == Surface.ROTATION_0 || Rotation == Surface.ROTATION_180) &&
            config.orientation == Configuration.ORIENTATION_LANDSCAPE)
        || ((Rotation == Surface.ROTATION_90 || Rotation == Surface.ROTATION_270) &&   
            config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
      Return Configuration.ORIENTATION_LANDSCAPE;
    } Else {
      Return Configuration.ORIENTATION_PORTRAIT;
    }
}
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…