如何使用Kotlin在Android Wear(Galaxy Watch 4)的背景下继续运行应用程序

发布于 2025-02-11 19:52:52 字数 154 浏览 1 评论 0原文

我正在使用三星手表4收集原始传感器数据(Heletrate,加速度计,陀螺仪等)。我需要在后台连续运行数据收集应用程序。但是,看来OS在一段时间后杀死了该应用程序。

因此,我的问题是 - 如何将我的应用程序连续运行,而不会被手表OS打断/杀死?

I am collecting raw sensor data (HeartRate, accelerometer, gyroscope, etc.) with Samsung Watch 4. I need to run my data collection application continuously in the background. However, it seems the watch OS kills the application after some time.

So my question is - How can I keep my application running in the background continuously without being interrupted/killed by the watch OS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弥繁 2025-02-18 19:52:52

健康服务 https://develoveler.android.com/training.com/training/training/wearables/wearables/wearables/health-services < /a>是处理此操作的方法,因此您不需要应用程序就可以始终运行。

但是,如果您需要加速度计和陀螺仪,那么您需要收集自己,那么您将不得不运行前景服务。

https://develoveling.com/guide.com/guide/guide/components/foreforgground-services/foreforgground-services

但是,如果您只想进行加速度计和陀螺仪移动来检测活动,那么WH可以为您做到这一点。

在此处查看一些样本 https://github.com/android/android/health-shealth-samples

Health Services https://developer.android.com/training/wearables/health-services is the way to handle this for heartrate, so you don't need your app to always be running.

But if you need accelerometer and gyro specifically you will need to collect yourself, then you will have to run a Foreground Service.

https://developer.android.com/guide/components/foreground-services

But if you just want accelerometer and gyro for movement to detect an activity, then WHS can do this for you.

See some of the samples here https://github.com/android/health-samples

蓬勃野心 2025-02-18 19:52:52

使用重力传感器时,我们遇到了同样的问题。我们试图继续屏幕以解决它,但这不是理想的方式,因为它会迅速降低电源。
这是我们使用的代码(Java):
getwindow()。addflags(windowmanager.layoutparams.flag_keep_screen_on)

We had the same problem when using gravity sensor. We tried to keep the screen on to solve it but it's not a ideal way because it will make the power down quickly.
Here is the code we used(Java):
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文