Android Wear: Measuring Sensors And Preventing Ambient Mode / Sleep
Solution 1:
1) Use a wake lock. To keep the CPU awake but let the screen go dim, you can use code like the following:
PowerManagerpowerMgr= (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerMgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
wakeLock.acquire(duration);
where TAG
is a string to indicate the component holding the wake lock, and duration
is measured in milliseconds.
I assume I don't need to warn you about the adverse battery effects of keeping the device from going into ambient. An average Wear device may or may not last for the solid hour you're proposing.
2) Yes. This is kind of the definition of a Service
, "an application component representing either an application's desire to perform a longer-running operation while not interacting with the user" (from https://developer.android.com/reference/android/app/Service.html).
3) Yes. I do this in a number of apps; there's no requirement that Data API calls need to be on the UI thread.
Post a Comment for "Android Wear: Measuring Sensors And Preventing Ambient Mode / Sleep"