最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flutter - Android Wear_OS 5, always-on and ambient mode - Stack Overflow

programmeradmin4浏览0评论

I am running Flutter in Android Studio. I have been working on an app for my Samsung Galaxy 7 ultra. I am using the wear_plus package to manage screen shape and size as well as ambient mode. My app is a simple countdown timer with some incremental audible beeps and sounds that get played (all working perfectly). I have ambient mode enabled on my device and the UI updates accordingly, when it comes back to interactive mode it updates appropriately.

My issue is that I seek to understand how to stop the OS from pushing the app to the background when it is in ambient mode for a period of time. I've spent some time looking here on the forums and I still can't quite seem to connect the dots. I've also read this.

But my confusion seems to lie in the fact that "always-on" seems to mean it can go to ambient mode, but not that it "always-on" means it can't be pushed to the background from ambient mode". For that this doc eludes to the fact that:

Always-on apps can move to the background

Starting in Wear OS 5, the system moves always-on apps to the background after they're visible in ambient mode for a certain period of time. Users can configure the timeout in system settings.

If your always-on app displays information about an ongoing user task—such as music playback or a workout session—you might want to keep the ongoing activity visible until the task ends. To do so, use the Ongoing Activity API to post an ongoing notification that is linked to your always-on activity.

Again, I think my key to doing what I want is in this explanation, but I might be a bit hard headed here and it's not sinking in. After reading through the Ongoing Activity API docs, it makes sense to me that "when the app gets pushed to the background" the user gets the notification icon at the bottom of an on-going activity like "media playing" , "ongoing workout", etc. and while I would eventually want to use this, I feel that I still want something in the middle.

Goal: Much like a fitness tracking app that monitors heart rate. The app should be allowed to transition between interactive and ambient mode, but when in ambient mode, not transition to background.

Flutter Doctor output:

 flutter doctor -v
[√] Flutter (Channel stable, 3.29.0, on Microsoft Windows [Version 10.0.19045.5487], locale en-US) [306ms]
    • Flutter version 3.29.0 on channel stable at C:\src\flutter
    • Upstream repository .git
    • Framework revision 35c388afb5 (9 days ago), 2025-02-10 12:48:41 -0800
    • Engine revision f73bfc4522
    • Dart version 3.7.0
    • DevTools version 2.42.2

[√] Windows Version (10 Pro 64-bit, 22H2, 2009) [1,594ms]

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [2.1s]
    • Android SDK at C:\Users\Justin\AppData\Local\Android\sdk
    • Platform android-35-ext14, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

[√] Chrome - develop for the web [24ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps [23ms]
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at /.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2024.2) [21ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       
    • Dart plugin can be installed from:
       
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)

[√] Connected device (4 available) [321ms]
    • sdk gwear x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Windows (desktop)         • windows       • windows-x64    • Microsoft Windows [Version 10.0.19045.5487]
    • Chrome (web)              • chrome        • web-javascript • Google Chrome 132.0.6834.197
    • Edge (web)                • edge          • web-javascript • Microsoft Edge 133.0.3065.69

[√] Network resources [400ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

I'm using the following packages:

flutter_ringtone_manager: ^1.1.2
 wear_plus: ^1.2.2
wakelock_plus: ^1.2.10
sensors_plus: ^6.1.1
hive_ce: ^2.10.1
hive_ce_flutter: ^2.2.0`

I have successfully used wakelock_plus to keep the screen in interactive mode, but this does not allow ambient mode. If I manually put the device in ambient mode, after a few seconds, the OS still pushes it to the background.

For now, I have commented out the Wakelock command for testing:

 //WakelockPlus.enable();
发布评论

评论列表(0)

  1. 暂无评论