我想知道 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/