Created
August 29, 2016 20:21
-
-
Save murki/29ba90d17d36fd9b2028ee4d8555a9e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SensorActivity extends Activity { | |
private static final String LOG_TAG = SensorActivity.class.getName(); | |
private SensorManager sensorManager; | |
private Sensor accelerometer; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); | |
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); | |
} | |
protected void onResume() { | |
super.onResume(); | |
sensorManager.registerListener(sensorListener, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); | |
} | |
protected void onPause() { | |
super.onPause(); | |
sensorManager.unregisterListener(sensorListener); | |
} | |
private final SensorEventListener sensorListener = new SensorEventListener() { | |
@Override | |
public void onSensorChanged(SensorEvent sensorEvent) { | |
Log.d(LOG_TAG, "onSensorChanged() - sensorEvent.timestamp=" + sensorEvent.timestamp + ", sensorEvent.values=" + Arrays.toString(sensorEvent.values)); | |
} | |
@Override | |
public void onAccuracyChanged(Sensor sensor, int i) { | |
// ignored for this example | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment