java.lang.Object | |
↳ | com.neomades.io.sensor.SensorManager |
A SensorManager
lets you access the device's sensors. Get an
instance of this class by calling getDefault()
, this
class can be instantiated only once. Then, you can get any sensor you want by
calling the appropriate getter. Always make sure to disable sensors you don't
need, especially when your application is paused. Failing to do so can drain
the battery in just a few hours. Note that the system will not disable
sensors automatically when the screen turns off.
public final class AccelerometerScreen extends Screen implements SensorListener { AccelerometerSensor accelerometer; SensorManager manager; protected void onCreate() { manager = SensorManager.getDefault(); if (manager.isAccelerometerSupported()) { accelerometer = manager.getAccelerometer(); accelerometer.setListener(this); } } public void onSensorChanged(Sensor sensor, SensorData data) { final AccelerometerData accData = (AccelerometerData) data; // allows to update the UI controller.runOnUiThread(new Runnable() { public void run() { // DO SOME STUFF... } }); } }
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
AccelerometerSensor |
getAccelerometer()
Gets an accelerometer sensor.
| ||||||||||
static SensorManager |
getDefault()
Returns the default SensorManager.
| ||||||||||
GyroscopeSensor |
getGyroscope()
Gets a gyroscope sensor.
| ||||||||||
MagnetometerSensor |
getMagnetometer()
Gets a magnetometer sensor.
| ||||||||||
boolean |
isAccelerometerSupported()
Indicates whether an accelerometer is available on the device.
| ||||||||||
boolean |
isGyroscopeSupported()
Indicates whether a gyroscope is available on the device.
| ||||||||||
boolean |
isMagnetometerSupported()
Indicates whether a magnetometer is available on the device.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Gets an accelerometer sensor.
You can get only one accelerometer per SensorManager instance. If the accelerometer is not supported then it returns a null object.
Returns the default SensorManager.
Gets a gyroscope sensor.
You can get only one gyroscope per SensorManager instance. If the gyroscope is not supported then it returns a null object.
Gets a magnetometer sensor.
You can get only one magnetometer per SensorManager instance. If the magnetometer is not supported then it returns a null object.
Indicates whether an accelerometer is available on the device.
Indicates whether a gyroscope is available on the device.
Indicates whether a magnetometer is available on the device.