0
我想製作一個應用程序,它在用戶單擊按鈕時顯示3軸以上的設備方向,但結果始終爲0.0 | 0.0 | 0.0(不旋轉),爲什麼?android-爲什麼我無法獲取設備定位?
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();
}
}