FWIW, the orientation sensor is deprecated. While I yanked the sensor
coverage from my books (the third-generation sensor API makes my head
hurt), I do have some samples that might help:

https://github.com/commonsguy/cw-advandroid/tree/master/Sensor

On Wed, Nov 16, 2011 at 8:46 AM, Raghav Sood
<raghavs...@androidactivist.org> wrote:
> Having a little problem here. I am making an app that uses the GPS,
> accelerometer and compass. GPS works fine. The problem comes with the other
> two. According to the Log.d s splattered all over my code, the following
> code receives the sensor events for the sensor with the int code 1, which
> according to the docs is the accelerometer.
>
> public void onSensorChanged(SensorEvent evt)
>
>   {
>
>       float vals[] = evt.values;
>
>       //Log.d("PAAR", "Sensor triggered.");
>
>       if(evt.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD ||
> evt.sensor.getType() == Sensor.TYPE_ORIENTATION)
>
>       {
>
>         float rawDirection = vals[0];
>
>         Log.d("PAAR", "compass Sensor triggered.");
>
>         direction =(float) ((rawDirection * kFilteringFactor) +
>
>             (direction * (1.0 - kFilteringFactor)));
>
>           inclination =
>
>             (float) ((vals[2] * kFilteringFactor) +
>
>             (inclination * (1.0 - kFilteringFactor)));
>
>
>
>           if(aboveOrBelow > 0)
>
>           {
>
>             inclination = inclination * -1;
>
>           }
>
>
>
>         if(evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
>
>         {
>
>             aboveOrBelow =
>
>               (float) ((vals[2] * kFilteringFactor) + (aboveOrBelow * (1.0 -
> kFilteringFactor)));
>
>             Log.d("PAAR", "Accelerometer ");
>
>         }
>
>       }
>
>   }
>
> Yet the if statement for the accelerometer doesn't kick in. Also why am I
> not receiving the compass events? My device has a compass, I am 100% sure of
> that. I register the sensors as follows:
>
> sensorManager =
> (SensorManager)this.getSystemService(Context.SENSOR_SERVICE);
>
>       sensorManager.registerListener(listener,
> sensorManager.getDefaultSensor( SensorManager.SENSOR_ORIENTATION),
> SensorManager.SENSOR_DELAY_FASTEST);
>
>       sensorManager.registerListener(listener,
> sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
> SensorManager.SENSOR_DELAY_FASTEST);
>
> Ideas/solutions, anyone?
>
> Thanks
>
> --
> Raghav Sood
> http://www.androidactivist.org/ - Author
> http://www.appaholics.in/ - Founder
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training...At Your Office: http://commonsware.com/training

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to