I'm writing my app for Android 1.1, so I have to use the old
deprecated SensorManager and SensorListener. The relevant code looks
like this:

class gpListener implements SensorListener
{
       public void onAccuracyChanged(int sensor, int accuracy)
       {
       }

       public void onSensorChanged(int sensor, float[] values)
       {
             if(sensor == SensorManager.SENSOR_ORIENTATION)
             {
                    _thread.aX = (int)(values[3]);
                    _thread.aY = (int)(values[2]);
                    Log.i("gpActivity", "aX= " + _thread.aX);
                    Log.i("gpActivity", "aY= " + _thread.aY);
             }
       }
}

Then inside _thread:

public gpListener sL;
public SensorManager sM;
Log.i("gpActivity", "trying to get sM");
sM = (SensorManager)(_context.getSystemService
(Context.SENSOR_SERVICE));
Log.i("gpActivity", "Should have, now trying to get sL");
sL = new gpListener();
@SuppressWarnings("unused")
boolean something = sM.registerListener(sL,
SensorManager.SENSOR_ORIENTATION, SensorManager.SENSOR_DELAY_GAME);
Log.i("gpActivity", "should have sL");

The log turns out:

gpActivity            trying to get sM
gpActivity            Should have, now trying to get sL
SensorService     could not enable sensor 1
gpActivity            should have sL

Obviously, aX and aY don't ever get the orientation values.

What am I doing wrong? Is there some sort of sample code for
SensorManager and SensorListener?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to