Tôi đang cố gắng lấy góc nghiêng, góc cuộn từ cảm biến của tôi từ điện thoại Android nhưng không thành công cho đến thời điểm này,lấy góc nghiêng Android
khi tôi nhấp vào nút của mình. , tôi nhận được "Kết quả: 0.0 -0,0 -0,0"
package com.example;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Button;
import android.view.View;
public class MyActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final float[] mValuesMagnet = new float[3];
final float[] mValuesAccel = new float[3];
final float[] mValuesOrientation = new float[3];
final float[] mRotationMatrix = new float[9];
final Button btn_valider = (Button) findViewById(R.id.btn1);
final TextView txt1 = (TextView) findViewById(R.id.textView1);
final SensorEventListener mEventListener = new SensorEventListener() {
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
// Handle the events for which we registered
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
System.arraycopy(event.values, 0, mValuesAccel, 0, 3);
break;
case Sensor.TYPE_MAGNETIC_FIELD:
System.arraycopy(event.values, 0, mValuesMagnet, 0, 3);
break;
}
};
};
btn_valider.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
SensorManager.getRotationMatrix(mRotationMatrix, null, mValuesAccel, mValuesMagnet);
SensorManager.getOrientation(mRotationMatrix, mValuesOrientation);
final CharSequence test;
test = "results: " + mValuesOrientation[0] +" "+mValuesOrientation[1]+ " "+ mValuesOrientation[2];
txt1.setText(test);
}
});
}
}
cảm ơn, mà đã làm nó –
những góc mang lại giá trị rất nhỏ và thậm chí nếu giữ trên bề mặt phẳng vẫn tiếp tục thay đổi giá trị –
@AashishVirendraKBhatnagar là trong radian + cảm biến không quá chính xác –