Query the accelerometer when the application is in the background
- Import the following classes:
- net.rim.device.api.system.AccelerometerChannelConfig;
- net.rim.device.api.system.AccelerometerSensor.Channel;
- Create a configuration for a channel to the accelerometer.
AccelerometerChannelConfig channelConfig = new AccelerometerChannelConfig( AccelerometerChannelConfig.TYPE_RAW );
- Invoke AccelerometerChannelConfig.setBackgroundMode(Boolean), to specify support for an application that is in the background.
channelConfig.setBackgroundMode( true );
- Invoke AccelerometerSensor.openChannel(), to open a background channel to the accelerometer.
Channel channel = AccelerometerSensor.openChannel( Application.getApplication(), channelConfig );
- Invoke Thread.sleep() to specify the interval between queries to the accelerometer, in milliseconds.
short[] xyz = new short[ 3 ];
while( running ) {
channel.getLastAccelerationData( xyz );
Thread.sleep( 500 );
}
- Invoke Channel.close() to close the channel to the accelerometer.
channel.close();
Was this information helpful? Send us your comments.