我想制作一个应用程序,在用户单击按钮时显示 3 个轴上的设备方向,但结果始终是 0.0|0.0|0.0 (no rotation) ,为什么?
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();
}
}