WearOS 始终开启模式无法在设备上运行

Posted

技术标签:

【中文标题】WearOS 始终开启模式无法在设备上运行【英文标题】:WearOS always-on mode not working on device 【发布时间】:2020-09-14 15:46:26 【问题描述】:

我是 WearOS 新手,我需要开发一个活动跟踪应用程序。我从 Google 为 Always-on 应用程序提供的示例开始。在模拟器中一切正常,从这个跟踪中可以看出:

2020-05-27 15:44:11.003 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587051002(false)
2020-05-27 15:44:12.002 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587052002(false)
2020-05-27 15:44:13.003 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587053003(false)
2020-05-27 15:44:14.003 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587054002(false)
2020-05-27 15:44:14.587 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: Ambient: onEnterAmbient
2020-05-27 15:44:14.587 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587054587(true)
2020-05-27 15:44:20.002 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587060002(true)
2020-05-27 15:44:30.003 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587070003(true)
2020-05-27 15:44:40.002 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587080002(true)
2020-05-27 15:44:50.005 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587090005(true)
2020-05-27 15:44:50.095 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: Ambient: onExitAmbient
2020-05-27 15:44:50.096 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587090096(false)
2020-05-27 15:44:51.002 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587091002(false)
2020-05-27 15:44:52.002 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587092002(false)
2020-05-27 15:44:53.002 4296-4296/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590587093002(false)

但是当我在真实设备(Suunto 7、WearOS 2.17)上尝试时,它不起作用。当我转动手腕时,应用程序没有进入环境模式,它给出了这个错误Error on detecting ambient animation,而不是调用onEnterAmbient(),它只是调用onPause()。一旦我点击显示屏,就会调用 onResume()。完整的跟踪在这里:

2020-05-27 16:34:41.002 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590081001(false)
2020-05-27 16:34:42.002 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590082002(false)
2020-05-27 16:34:43.001 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590083001(false)
2020-05-27 16:34:44.002 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590084001(false)
2020-05-27 16:34:45.002 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590085002(false)
2020-05-27 16:34:45.657 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: onPause()
2020-05-27 16:34:45.755 13984-13984/com.example.android.wearable.wear.alwayson E/ViewRootImpl[MainActivity]: Error on detecting ambient animation
2020-05-27 16:34:50.339 13984-13984/com.example.android.wearable.wear.alwayson W/ViewRootImpl[MainActivity]: Dropping event due to no window focus: MotionEvent  action=ACTION_HOVER_ENTER, actionButton=0, id[0]=0, x[0]=99.78022, y[0]=99.78022, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=221271754, downTime=221262644, deviceId=2, source=0x1002 
2020-05-27 16:34:50.362 13984-13984/com.example.android.wearable.wear.alwayson W/ViewRootImpl[MainActivity]: Dropping event due to no window focus: MotionEvent  action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=99.78022, y[0]=99.78022, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=221271754, downTime=221262644, deviceId=2, source=0x1002 
2020-05-27 16:34:50.375 13984-13984/com.example.android.wearable.wear.alwayson W/ViewRootImpl[MainActivity]: Cancelling event due to no window focus: MotionEvent  action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=99.78022, y[0]=99.78022, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=221271791, downTime=221262644, deviceId=2, source=0x1002 
2020-05-27 16:34:50.377 13984-13984/com.example.android.wearable.wear.alwayson I/chatty: uid=10078(com.example.android.wearable.wear.alwayson) identical 2 lines
2020-05-27 16:34:50.379 13984-13984/com.example.android.wearable.wear.alwayson W/ViewRootImpl[MainActivity]: Cancelling event due to no window focus: MotionEvent  action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=99.78022, y[0]=99.78022, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=221271791, downTime=221262644, deviceId=2, source=0x1002 
2020-05-27 16:34:50.387 13984-13984/com.example.android.wearable.wear.alwayson W/ViewRootImpl[MainActivity]: Dropping event due to no window focus: MotionEvent  action=ACTION_HOVER_ENTER, actionButton=0, id[0]=0, x[0]=99.78022, y[0]=99.78022, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=221271792, downTime=221262644, deviceId=2, source=0x1002 
2020-05-27 16:34:50.389 13984-13984/com.example.android.wearable.wear.alwayson W/ViewRootImpl[MainActivity]: Dropping event due to no window focus: MotionEvent  action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=99.78022, y[0]=99.78022, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=221271792, downTime=221262644, deviceId=2, source=0x1002 
2020-05-27 16:34:50.391 13984-13984/com.example.android.wearable.wear.alwayson W/ViewRootImpl[MainActivity]: Cancelling event due to no window focus: MotionEvent  action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=99.78022, y[0]=99.78022, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=221271805, downTime=221262644, deviceId=2, source=0x1002 
2020-05-27 16:34:50.394 13984-13984/com.example.android.wearable.wear.alwayson I/chatty: uid=10078(com.example.android.wearable.wear.alwayson) identical 2 lines
2020-05-27 16:34:50.395 13984-13984/com.example.android.wearable.wear.alwayson W/ViewRootImpl[MainActivity]: Cancelling event due to no window focus: MotionEvent  action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=99.78022, y[0]=99.78022, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=221271805, downTime=221262644, deviceId=2, source=0x1002 
2020-05-27 16:34:50.503 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: onResume()
2020-05-27 16:34:50.507 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590090507(false)
2020-05-27 16:34:51.002 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590091002(false)
2020-05-27 16:34:52.002 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590092002(false)
2020-05-27 16:34:53.002 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590093001(false)
2020-05-27 16:34:54.001 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590094001(false)
2020-05-27 16:34:55.001 13984-13984/com.example.android.wearable.wear.alwayson D/MainActivity: loadDataAndUpdateScreen(): 1590590095001(false)

我做错了吗?该代码正是谷歌here提供的代码。关于如何解决它的任何线索? 谢谢

【问题讨论】:

【参考方案1】:

我发现了问题。要使此模式正常工作,必须在 Settings -> Display -> Always-on screen 中将显示设置为始终开启。 这并不是我真正想要的,因为 Suunto 应用程序可以在不激活此模式的情况下实现这一点,但我想这是因为它是一个系统应用程序。

【讨论】:

有没有办法以编程方式检测该用户设置是打开还是关闭?我设置了一个问题:***.com/questions/70968373/…

以上是关于WearOS 始终开启模式无法在设备上运行的主要内容,如果未能解决你的问题,请参考以下文章

Wear OS - 如何在设备重启时自动启动应用程序

无法在我的设备上安装构建(始终需要重新连接设备)

小米note adb无法识别

VMware 无法连接虚拟设备ide1:0,主机上没有相对应的设备,您 要在每次开启此虚拟机时都尝试连接此虚拟设备吗?

颤振互联网连接无法在真实设备上运行

推送通知在开发模式下无法在 iOS 上运行