I'm new to WearOS, I need to develop an activity tracking application. I'm starting from the example provided by Google for Always-on applications. In the emulator everything works fine as can be seen from this trace:
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)
But when I try on a real device (Suunto 7, WearOS 2.17) it does not work. When I turn the wrist, the application does not enter ambient mode, it gives this error Error on detecting ambient animation
and instead of calling onEnterAmbient()
it just calls onPause()
. As soon as I tap the display, onResume() is called. Full trace here:
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)
Am I doing something wrong? The code is exactly the one provided by Google here. Any clue about how to solve it? Thanks
I found the problem. To get this modality to work the display has to be set as always on in Settings -> Display -> Always-on screen. This is not really what I wanted since the Suunto app can achieve this without this modality being active, but I guess it's due to the fact that it is a system application.