gpt4 book ai didi

android - 检查android设备旋转是否可行

转载 作者:搜寻专家 更新时间:2023-11-01 08:27:51 25 4
gpt4 key购买 nike

我想知道android设备是否支持设备旋转。我以为任何 Android 设备都支持屏幕旋转,但我的 Samsung Galaxy View 不支持任何旋转。

我只找到这段代码:

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();
}

但这只会让我知道用户是否将屏幕旋转设置为关闭或打开,我想知道这是否完全可行。

请帮帮我,最良好的祝愿

狮子座

最佳答案

您可以检查传感器 的可用性。这是官方docs

PackageManager manager = getPackageManager();
boolean hasAccelerometer = manager.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);

加速度计的作用

The accelerometer is a built-in electronic component that measures tilt and motion. It is also capable of detecting rotation and motion gestures such as swinging or shaking.

The most common use for it is to activate auto screen rotation on mobile devices when the user changes their orientation from portrait to landscape or vice-versa.

关于android - 检查android设备旋转是否可行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43092700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com