Hi!! I'm making an application on Android and I'm using the accelerometer sensor of my phone.
Part of the code is:
I want to use the x,y and z values on another method, but even they are global variables, if I call them just like that on the other method, thee only give the "null" value (cause it's a void method).
How can I do it???
Thanks.
Part of the code is:
Code:
public class OtroacelbtActivity extends Activity implements SensorEventListener {
private float x = 0, y = 0, z = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
List<Sensor> sensors = sm.getSensorList(Sensor.TYPE_ACCELEROMETER);
if (sensors.size() > 0) {
sm.registerListener(this, sensors.get(0), SensorManager.SENSOR_DELAY_UI );
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
@Override
public void onSensorChanged(SensorEvent event) {
synchronized (this) {
String message=null;
x = event.values[0];
y = event.values[1];
z = event.values[2];
}
}
}
How can I do it???
Thanks.