Is it possible to use the accelerometer in a background service?

by John Smith » Thu, 10 Sep 2009 01:05:47 GMT


Sponsored Links
 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?

--~--~---------~--~----~------------~-------~--~----~



Is it possible to use the accelerometer in a background service?

by Mike Collins » Thu, 10 Sep 2009 01:43:01 GMT


 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




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Is it possible to use the accelerometer in a background service?

by dadical » Thu, 10 Sep 2009 02:46:05 GMT


 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());
                }

        }





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. <WTA> Signal im3....

radionya untuk yg dream dah yg latest itu, amonra recovery ga ada ngaruh ke
signal...

coba lock ke 2g only gmana kualitas signalnya...

sent from Milestonewith  | read www.tux.or.id & http://bit.ly/aSTXL0 for
more android info




senior2 mw tny donk ko akhir2 ini sinyal im3 saya di dream melemah bahkan ga
ada sm sekali pdhal punya tmn saya ditempat yg sm sinyalnya penuh
apakah pengaruh klo ga pernah update baseband radio sama amon ra nya
yg saya updet terus cm rom cyannya sdngakan amon ra sm radio msi pke yg lama

status phone:
firmware version 1.6
baseband radio 62.50S.20.17U_2.22.19.26I
kernel version 2.6.29.6-cm42sh...@toxygene
mod version cyanogen mod-4.2.14.1
build number DRC83

mhon pencerahannya mangstah...

-- 
"Indonesian Android Community [id-android]"

2. Operator 3 mulai....

Waduh.......belum sebulan dah mulai....terutama di rumah (Green Ville)

Semalem berasa lambat banget.......padahal sinyal 3G (oya logo-nya gak bisa H ya ? Spica langsung H lho dgn 3 :D ) Pas iseng test pake speedtest cuma dapet................................. 0,01mbps dooh!!! ---> pas ada dua Dream dan sama make 3 juga....test....sama aja..... TFlash Unlimited tutup gak yah ? -- Jus* ~ send using pc jangkrik krik krik ~ -- "Indonesian Android Community [id-android]"

3. TableLayout with fixed row & column

4. Market Intent Suggestion

5. android console shell

6. Update3: Kloteran External Battery 4400mAh - Just Mobile Gum Pro & Gum Plu

7. Horizontal Mode for Messaging