0
I am developing an android application that uses the ACCELEROMETER sensor. I need to measure the inclination in degrees. I was able to instantiate the sensor to measure it, display the X, Y and Z axes in Textviews. However, the values that the sensor returns to me are not in degrees. I searched to see if it was in which unit this data is displayed/measured by the ACCELEROMETER, but without success. From now on I thank anyone who can help me.
//Atributos para trabalhar com a camera
private Camera camera;
private FrameLayout frameLayout;
private ShowCamera showCamera;
//Atributos para trabalhar com os eixos
private TextView textViewX;
private TextView textViewY;
private TextView textViewZ;
//Atributos para trabalhar com o Acelerometro
private Sensor sensor;
private SensorManager sensorManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.frameLayout = (FrameLayout) findViewById(R.id.frameLayoutCamera);
this.camera = Camera.open();
this.showCamera = new ShowCamera(this, camera);
this.frameLayout.addView(showCamera);
textViewX = (TextView) findViewById(R.id.textViewX);
textViewY = (TextView) findViewById(R.id.textViewY);
textViewZ = (TextView) findViewById(R.id.textViewZ);
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorManager.registerListener(MainActivity.this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
public void onSensorChanged(SensorEvent event) {
textViewX.setText("" + event.values[0]);
textViewY.setText("" + event.values[1]);
textViewZ.setText("" + event.values[2]);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
I suppose you’re using the wrong sensor.
– ramaral
Which sensor would be suitable for measuring inclination in degrees?
– RDamazio
You have to use two, see the documentation
– ramaral