java - SensorManager 仅适用于某些设备
问题描述
我有以下代码来获取设备的 x 和 y 角度,它在我的手机上运行良好,但在我的平板电脑(三星 Galaxy Tab e)上运行良好。我想知道是否有人知道是什么导致它在一台设备上工作而不是在另一台设备上工作。
我还确保两者都启用了屏幕旋转。我的假设是平板电脑缺少传感器,而我最想要的是一种解决方法。任何帮助将非常感激。提前致谢!
源代码:
double yAngle;
double xAngle;
@Override
protected void onResume() {
super.onResume();
sensorManager.unregisterListener(this);
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR),RATE);
}
@Override
public void onSensorChanged(SensorEvent event) {
float[] rotationMatrix;
rotationMatrix = new float[16];
SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);
determineOrientation(rotationMatrix);
lblY.setText(String.format("%.1f", yAngle));
lblX.setText(String.format("%.1f", xAngle));
}
private void determineOrientation(float[] rotationMatrix){
//CREATING FLOAT ARRAY OF ORIENTATION VALUES
float [] orientationValues = new float[3];
SensorManager.getOrientation(rotationMatrix, orientationValues);
yAngle = Math.toDegrees(orientationValues[2]);
xAngle = Math.toDegrees(orientationValues[1]);
}
解决方案
您可以使用它adb shell pm list features
来检查所有传感器和支持的其他功能。
推荐阅读
- javascript - 您如何调整 CSS 以修复因关键帧更改背景图像而导致的闪烁?
- .net - NU1202:包与 net50-windows 不兼容
- rust - 为 thumbv7m-none-eabi 构建时如何避免“E0463: can't find crate for `test` can't find crate”?
- javascript - Ajax 完成后保持过滤器导航项“活动”
- reactjs - Tailwind 变体不适用于 PostCSS
- angular - 如何仅使用 ngx-paypal 模块中的“PayPal”按钮?
- visual-studio - 命令“SFDX:创建项目”导致错误(未找到命令“sfdx.force.project.create”)
- sql - 如果表为空,Raiserror Proc
- go - 具有多个结构的共同功能
- jenkins - 无法 curl 以保护来自本地 minikube 集群的 HTTP