Last active
August 29, 2015 14:18
-
-
Save forceLain/2c7930143d5a4e467c70 to your computer and use it in GitHub Desktop.
simple sensor listener
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, implements SensorEventListener { | |
private final SensorManager sensorManager; | |
private final Sensor accelerometer; | |
public SensorActivity() { | |
sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); | |
accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); //Датчик освещённости | |
} | |
protected void onResume() { | |
super.onResume(); | |
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); //Подключаемся к сенсору | |
} | |
protected void onPause() { | |
super.onPause(); | |
sensorManager.unregisterListener(this); //Отключаемся от сенсора | |
} | |
public void onAccuracyChanged(Sensor sensor, int accuracy) { | |
} | |
public void onSensorChanged(SensorEvent event) { | |
//Получаем данные из SensorEvent | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment