Used for receiving notifications from the SensorManager when sensor values have changed.
1. In the MainActivity.java file, add the lines below to the import section.
import android.hardware.SensorEventListener;
import android.hardware.SensorEvent;
2. Add the below code to the onCreate method. This will add a SensorEventListener named mySensorEventListener. Toasts were added for testing.
SensorEventListener mySensorEventListener = new SensorEventListener(){
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
Toast.makeText(getBaseContext(), "onAccuracyChanged", Toast.LENGTH_LONG).show();
}
@Override
public void onSensorChanged(SensorEvent event) {
Toast.makeText(getBaseContext(), "onSensorChanged", Toast.LENGTH_LONG).show();
}
};3. Compile and run!
Resources:
http://developer.android.com/reference/android/hardware/SensorEventListener.html
http://developer.android.com/reference/android/hardware/SensorEvent.html