Query the accelerometer when the application is in the foreground

  1. Import the following classes:
    • net.rim.device.api.system.AccelerometerChannelConfig
    • net.rim.device.api.system.AccelerometerSensor.Channel
  2. Open a channel to retrieve acceleration data from the accelerometer.
    Channel channel = AccelerometerSensor.openRawAccelerationChannel( Application.getApplication());
  3. 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 );
  4. Invoke Channel.close() to close the channel to the accelerometer.

Was this information helpful? Send us your comments.