I register a listener to orientation sensor from within a background
service with no trouble.  Perhaps the following code may help.  These
methods are called from my service's onCreate and onDestroy methods:

        private void startMonitoring(){
                SensorManager lMgr = (SensorManager) getSystemService
(Context.SENSOR_SERVICE);

                try{
                        lMgr.unregisterListener(this);
                } catch(Exception e){
                        Log.d(ScreeblService.class.getSimpleName(), 
e.toString());
                }

                List<Sensor> lSensorList = lMgr.getSensorList
(Sensor.TYPE_ORIENTATION);
                if(lSensorList == null || lSensorList.size() == 0){
                        throw new RuntimeException("Orientation sensor not 
available!");
                }

                                // assumes that this class implements
SensorEventListener
                lMgr.registerListener( this, lSensorList.get(0),
SensorManager.SENSOR_DELAY_NORMAL );

        }

        private void stopMonitoring(){
                SensorManager lMgr = (SensorManager) getSystemService
(Context.SENSOR_SERVICE);

                try{
                        lMgr.unregisterListener(this);
                } catch(Exception e){
                        Log.d(ScreeblService.class.getSimpleName(), 
e.toString());
                }

        }


On Sep 9, 1:41 pm, Mike Collins <[email protected]> wrote:
> my service uses "getBaseContext()", seems to work just fine.  Don't
> use it for
> GPS but we do use it for many other things.
>
>   mike
>
> On Sep 9, 6:57 am, John Smith <[email protected]> wrote:
>
>
>
> > It seems trivial to use GPS in a background service, but how can you
> > do the same with the accelerometer?
>
> > Everything I've tried seems to require a context, but a background
> > service doesn't have a context?- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to