Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Development

New Contributor
Posts: 2
Registered: ‎03-07-2012
My Device: Developer
My Carrier: .

Compass readings for Android Playbook app

I'm trying to build an Android app for the Playbook that reads orientation data from the sensors. My code works in a standard Android environment, but is refusing to work here.


I've tried both the following:

  • SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); 
    Sensor defaultOrient = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mSensorManager.registerListener(mySensorEventListener, defaultOrient, SensorManager.SENSOR_DELAY_UI);

    But the listener's methods are never called.

  • Using 
    SensorManager.getRotationMatrix and 
    but as these rely on reading data from the accelerometer and magnetometer in the same way as the first method, these are useless.


I unfortinately don't have a real Playbook and so have been relying on the emulator for development. I would assume that the emulator simply lacked the feature to produce any sensor readings, but I have also submitted a version of my app to Blackberry and they said that the compass wasn't working properly either.


Has anyone got a compass running properly in an Android Playbook app?


Posts: 10
Registered: ‎02-12-2012
My Device: simulator
My Carrier: O2

Re: Compass readings for Android Playbook app

I made a compass app that got accepted, it used this code
private final SensorListener sensorListener = new SensorListener()
public void onAccuracyChanged(int paramInt1, int paramInt2)

public void onSensorChanged(int paramInt, float[] paramArrayOfFloat)
CompassActivity.this.updateOrientation(paramArrayOfFloat[2], paramArrayOfFloat[1], paramArrayOfFloat[0]);
SensorManager sensorManager;

private void updateOrientation(float paramFloat1, float paramFloat2, float paramFloat3)
if (this.compassView != null)

then in constructor:

this.sensorManager = ((SensorManager)getSystemService("sensor"));
updateOrientation(0.0F, 0.0F, 0.0F);