Query The Accelerometer When The Application Is In The Background; Store Accelerometer Readings In A Buffer - Blackberry JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE Manual

Version: 4.7.0
Hide thumbs Also See for JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE:
Table of Contents

Advertisement

Development Guide
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 );
14
Working with the accelerometer of a BlackBerry device

Advertisement

Table of Contents
loading

This manual is also suitable for:

Java development environment

Table of Contents