How do I get the CURRENT orientation (ActivityInfo.SCREEN_ORIENTATION_*) of an Android device?

后端 未结 8 2014
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 03:05

I would like to find out the detailed orientation of a device, preferably one of SCREEN_ORIENTATION_LANDSCAPE, SCREEN_ORIENTATION_PORTRAIT, S

8条回答
  •  心在旅途
    2020-11-27 03:17

    You could do it in a very simple way: get the screen widhtand height. screen width will be always higher when device is in landscape orientation.

    Display display = getWindowManager().getDefaultDisplay();
        int width = display.getWidth(); 
        int height = display.getHeight();
        Toast.makeText(getApplicationContext(), "" + width + "," + height,
                Toast.LENGTH_SHORT).show();
        if (width > height) {
            Toast.makeText(getApplicationContext(), "LandScape",
                    Toast.LENGTH_SHORT).show();
        }
    

提交回复
热议问题