Android Question OS Wear Ambient mode refresh screen

Discussion in 'Android Questions' started by Alexander Stolte, Oct 28, 2018.

  1. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed 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: Oct 28, 2018
  2. alwaysbusy

    alwaysbusy Expert Licensed 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.
     
  3. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    it was very easy, too easy. :rolleyes:

    all what you need is this:
    Code:
    Sub Ambient_Enter(IsLowBitAmbient As Boolean, DoBurnInProtection As Boolean)
        
    Log("Ambient enter")
    StartService(Starter)
    End Sub
     
    alwaysbusy likes this.
  4. alwaysbusy

    alwaysbusy Expert Licensed User

    So the big lesson here is: B4A makes complex tasks easy :p
     
    Erel and DonManfred like this.
  5. DonManfred

    DonManfred Expert Licensed User

    You should not start the starter service manually. You should have used another service for this i guess.
     
    Erel likes this.
  6. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    it worked 3 times, but never after that.

    maybe this is the solution, i try it this evening
     
    Last edited: Oct 30, 2018
  7. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    JUST A NOTE FOR ME:
    Code:
    #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
     
  8. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    ok, i did it!!!!!

    only what you need is this:
    Code:
    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
     
    alwaysbusy and mindful like this.
  9. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    And here a Screenshot of my app:
    Snapchat-1537955763__01.jpg
    On top, the Total time of my Training and on the bottom is a timer of 1 minute, after this, the App Vibrate and i can train the next round.
     
    alwaysbusy, DonManfred and mindful like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice