4.
Invoke
Channel.close()
to close the channel to the accelerometer.
channel.close();
Query the accelerometer when the application is in the background
1.
Import the following classes:
•
net.rim.device.api.system.AccelerometerChannelConfig;
•
net.rim.device.api.system.AccelerometerSensor.Channel;
2.
Create a configuration for a channel to the accelerometer.
AccelerometerChannelConfig channelConfig = new AccelerometerChannelConfig
( AccelerometerChannelConfig.TYPE_RAW );
3.
Invoke
AccelerometerChannelConfig.setBackgroundMode(Boolean)
, to specify support for an
application that is in the background.
channelConfig.setBackgroundMode( true );
4.
Invoke
AccelerometerSensor.openChannel()
, to open a background channel to the accelerometer.
Channel channel = AccelerometerSensor.openChannel
( Application.getApplication(), channelConfig );
5.
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 );
}
6.
Invoke
Channel.close()
to close the channel to the accelerometer.
channel.close();
Store accelerometer readings in a buffer
1.
Import the following classes:
•
net.rim.device.api.system.AccelerometerChannelConfig;
•
net.rim.device.api.system.AccelerometerSensor.Channel;
2.
Create a configuration for a channel to the accelerometer.
AccelerometerChannelConfig channelConfig = new AccelerometerChannelConfig
( AccelerometerChannelConfig.TYPE_RAW );
3.
Invoke
AccelerometerChannelConfig.setSamplesCount()
, to specify the number of acceleration
readings to store in the buffer. Each element in the buffer contains acceleration readings for the X, Y, and Z axes and data
on when the reading took place.
channelConfig.setSamplesCount( 500 );
Development Guide
Working with the accelerometer of a BlackBerry device
14