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. Android market rules are changed, you must accept it within 30 days but...

On Mon, Jul 26, 2010 at 2:24 AM, William Ferguson



My experience up to now has been "almost zero".


-- 
Greg Donald
destiney.com | gregdonald.com

-- 

2. Numeric Keypad on WebView

Hi,

Android 2.1

I am having a textbox in the the webview where only numeric input is
require but when the soft keypad pops up, it shows the full qwerty
keypad. As we know that few tags of HTML 5 is supported in android 2.1
and this also can be achieved by putting some javascript in the web
page but that is making the user experience very bad.

Is there any way to show only numeric keypad or is there any way to
grab the event where whenever any text box is focused so that I can
set its IME and CLASS as defined in EditorInfo.

Vishal

-- 

3. JNI in android

4. Getting a FileDescriptor from a Socket

5. Blank black screen while transiting to new activity.

6. Eclipse/Android environment issues

7. ContactsContract.RawContacts two entry get Inserted for single contact why so ?