找出设备方向是否锁定(检测是否启用了自动旋转) [英] Find out if device orientation is locked (Detect if auto-rotate is enabled/disabled)

查看:77
本文介绍了找出设备方向是否锁定(检测是否启用了自动旋转)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定设备的屏幕方向被锁定?我正在使用OrientationEventListener触发我的应用程序中的某些操作,如果用户的屏幕锁定,我想禁用这些操作.

How can I find out is device's screen orientation locked? I am using OrientationEventListener to trigger some actions inside my app which I would like to disable if user has his screen locked.

我知道我通常可以这样定位,但是如何找出这种锁定的定位:

I know I can usually can orientation like this but how to find out is this locked orientation:

    int orientation = getResources().getConfiguration().orientation;

    if (orientation == Configuration.ORIENTATION_PORTRAIT) {
        // It's portrait
    } else {
        // It's landscape
    }

推荐答案

使用此:

if (android.provider.Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1){
        Toast.makeText(getApplicationContext(), "Auto Rotate is ON", Toast.LENGTH_SHORT).show();

    }
    else{
        Toast.makeText(getApplicationContext(), "Auto Rotate is OFF", Toast.LENGTH_SHORT).show();
    }

这篇关于找出设备方向是否锁定(检测是否启用了自动旋转)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆