Ast*_*ron 4 android android-orientation
如何确定设备的屏幕方向是否已锁定?我正在使用OrientationEventListener来触发我的应用程序中的一些操作,如果用户屏幕被锁定,我想禁用它们.
我知道我通常可以这样定位,但如何找出这个锁定的方向:
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
// It's portrait
} else {
// It's landscape
}
Run Code Online (Sandbox Code Playgroud)
And*_*tel 20
用这个:
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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2630 次 |
| 最近记录: |