[英]android-why I can't get device orientation?
I want to make an app which shows device orientation over 3 axises while the user clicks on a button, but the result always is 0.0|0.0|0.0 (no rotation) , why? 我想制作一个可以在用户单击按钮时在3个轴上显示设备方向的应用程序,但结果始终是0.0 | 0.0 | 0.0(不旋转),为什么?
package com.example.newp;
import android.app.Activity;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class FullscreenActivity extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_fullscreen);
}
public void onButtonClick(View view) {
float[] mGravs = new float[3];
float[] mGeoMags = new float[3];
float[] mRotationM = new float[9];
float[] mInclinationM = new float[9];
float[] mOrientation = new float[3];
SensorManager.getRotationMatrix(mRotationM, mInclinationM, mGravs,
mGeoMags);
SensorManager.getOrientation(mRotationM, mOrientation);
Toast.makeText(
this,
String.valueOf(mOrientation[0]) + "|"
+ String.valueOf(mOrientation[1]) + "|"
+ String.valueOf(mOrientation[2]), Toast.LENGTH_LONG)
.show();
}
}
You are feeding in the wrong values. 您输入的值有误。 mGravs is [0.0, 0.0, 0.0] and so is mGeoMags. mGravs是[0.0,0.0,0.0],mGeoMags也是如此。 These values should come from sensor TYPE_ACCELEROMETER
and TYPE_MAGNETIC_FIELD
respectively. 这些值应分别来自传感器TYPE_ACCELEROMETER
和TYPE_MAGNETIC_FIELD
。 You can use the values returned by SensorEvent
of these sensors. 您可以使用这些传感器的SensorEvent
返回的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.