Android Question OS Wear Ambient mode refresh screen

Alexander Stolte

Expert
Licensed User
Longtime User
Hello,

i use the new wear os lib., on my watch, the Ambient mode is active after 30 seconds and the ui is not updating.

How can i update the UI during the Ambient mode?
 
Last edited:

alwaysbusy

Expert
Licensed User
Longtime User
In ambient mode, your screen is only updated once a minute or so. If you want to update it more frequently, this will be more complex and you will have to create some service, a "com.example.android.wearable.wear.alwayson.action.AMBIENT_UPDATE" intent and use StartServiceAtExact. I don't know exactly how this would work and this would require some advanced B4A stuff I imagine (probably also some changes in the manifest xml)

Here are some good reads I found but you will have to put the puzzle together yourself:

https://www.b4x.com/android/forum/threads/automatic-foreground-mode.90546

A Java example, here the most interesting part is the comments to find out what the culprits of doing such a thing as you want (like the restarting of the activity stuff looks interesting):
https://github.com/googlesamples/an...roid/wearable/wear/alwayson/MainActivity.java

From what I can get out of it, once an app goes in ambient mode, it can't wake up the processor so you must have a scheduled service that is called at a certain time, and when finished you will have to schedule the next update and so on.

There is probably a reason it isn't easy to do, as such apps can quickly drain the battery of your watch. In my golf app, I have to 'wake up' my watch (by wiggling my hand) to update the screen and see the latest GPS calculations.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
JUST A NOTE FOR ME:
B4X:
#If JAVA
import android.os.PowerManager;

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

}
#End If
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
ok, i did it!!!!!

only what you need is this:
B4X:
Sub Ambient_Enter(IsLowBitAmbient As Boolean, DoBurnInProtection As Boolean)
    Log("Ambient enter")

    StartServiceAtExact(Starter,DateTime.Now + 1000,True)

End Sub
the +1000 is for a interval of 1 second.
Thx B4A for the easy way of programming.

here is a link for a java project, so much do the java developers have to write.:D
 
Upvote 0
Top