[英]SensorManager only working on some devices
我有以下代碼來獲取設備的x和y角,並且它在手機上可以正常工作,但在平板電腦上不能正常工作(三星銀河標簽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
來檢查所有傳感器和支持的其他功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.