Friday, 15 January 2010

android - Use TYPE_STEP_DETECTOR when screen off -


I am developing an application that uses TYPE_STEP_DETECTOR. I want to know whether the user should also run on the screen Whether or not it is But the sensor TYPE_STEP_DETECTOR does not work when the screen is off, so I use Power Manager / Wacock to make the CPU not hibernate. But it still does not work, as a comparison, I add a magnetic sensor listener and phase detector listener of my demo app, when on the screen, both can get data, but when the screen turns off , Then only can get magnetic sensor data.

  Power Manager Manager = (Power Manager) getSystemService (Event.POWER_SERVICE); MWakeLock = manager.newWakeLock (PowerManager.PARTIAL_WAKE_LOCK, ""); MWakeLock.acquire ();  

then:

  stepDetectorSensor = sensorManager.getDefaultSensor (sensor.TYPE_STEP_DETECTOR); Sensor Manager. Registry Listener (Steppector Loistner, Steppector Sensor, Sensor Manager, SNSNR_Dele_NORML);  

then:

  Magnetaseer = sensor manager .get default sensor (sensor.Tep_magentiiiiiiiiiiii); Sensor Manager. Registry Listener (Magnetoassor Leastner, Magnet Sensor, Sensor Manager. SENSOR_DELAY_NORMAL);  

and:

  stepDetectorListener = new sensorventilistner () {@orride public invalidity change (sensor arg0, int arg1) {} @ override sensor changes public void SensorEvent arg0) {// no data when screen is off}}; MagnetSensorListener = New Sensor Event Listener () {@Averride overwrite Public Zero at SensorChanged {SensorEvent arg0} {// data off screen when}}; Changed compatibility on Public Zero (sensor arg0, int arg1) {} @}  

If you want to see that the user is running - you are completely different Take the view. Google released one of these settings to allow you to track the user's current activity (such as, and others).

It allows to track activity even when it is in the background.


No comments:

Post a Comment