Kyle Petryszak
Kyle Petryszak

Reputation: 116

Android Wear - How (if possible) to keep processor awake in ambient mode?

With the new addition of the "always on" api in a recent update with android wear, naturally I am trying to incorporate it into my fitness application. After doing some heavy reading on the android developers website it seems as though the only way to wake up the processor in ambient mode is to use an alarm manager. However this method is not very consistent or accurate.

1) With the alarm set to wake the processor and change the time on the screen after 3 seconds, it bounces around between 5-10 seconds.

2) Most of the time the method onEnterAmbient() is not even called until about a minute into being in ambient mode (the handler is still running and updating the screen at normal frequency)

3) Overall if anyone knows a different way to push updates to the screen while in ambient mode that would fantastic! (Mainly I believe there is another way due to the fact that watchfaces are able to update and show animations every second while in ambient mode)

Upvotes: 2

Views: 633

Answers (1)

dunqan
dunqan

Reputation: 974

You can keep processor running in ambient mode by utilizing wake lock:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "awake");
wl.acquire(30000);  // with 30s timeout or manually via wl.acquire() wl.release()

But you must take into consideration increased power usage which is not good idea in ambient mode.

Upvotes: 3

Related Questions