如果可能,我如何确保我的服务能收到我的可穿戴消息?

How can I ensure my service will get my Wearable Messages if possible?

我正在构建一个应用程序,它需要 - 假设设备能够通信 - 立即从 Android Wear 发送消息以在设备上执行方法。

我这样做的方法是创建一个等待消息的服务。我读过使用 START_STICKY 确保服务始终运行,以及如何在启动时启动它。

这是要走的路吗?还是我应该使用广播接收器?推荐的方法是什么?

根据 Listen for Data Layer events documentation, the correct method for handling incoming messages while the app is not in the foreground is by implementing a WearableListenerService - 它会在另一台设备(例如您的 Wear 设备)发送消息时自动调用。

您的 WearableListenerService 然后可以触发它想要的任何行为。