我有以下代码来获取我的设备的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]);
}发布于 2019-02-11 23:33:06
您可以使用adb shell pm list features检查所有支持的传感器和其他功能。
https://stackoverflow.com/questions/53352181
复制相似问题