如何从手持设备在可穿戴设备上启动服务(对光数据进行采样)?

How to start a Service (that samples light data) on a wearable from a handheld device?

我是 Android 开发的新手,我目前正在试验可穿戴应用程序。

我在我的智能手表上创建了一个后台服务,用于对光传感器数据进行采样,我希望它在每天的特定时间启动。我目前的方法是在我的手持设备上实现一个警报管理器来触发手表上的上述服务,但我不确定如何在 phone 和手表之间建立这种连接。

根据我的研究,我不确定这是否可能。我想我的主要问题是:

  1. 是否可以使用在我的 phone 上实现的警报管理器 在我的手表上启动服务? (我希望以后能把开始时间用户配置得这么理想,我希望这可以在phone上完成!)
  2. 如果是这样,如何做到这一点?我知道可以使用 messageApi 或广播接收器,但我不确定...?
  3. 如果不是,那么在可穿戴应用程序中实现闹钟会不会效率低下或被认为是糟糕的设计?

如有任何帮助,我们将不胜感激!

1.是否可以使用在我的 phone 上实现的警报管理器在我的手表上启动服务?

还没有尝试过,但请尝试查看 Building Apps for Wearables 文档,它将教您如何在手持应用程序中构建自动同步到可穿戴设备的通知,以及如何构建应用程序 运行 在可穿戴设备上。


2.如果可以,请问如何实现?我知道可以使用 messageApi 或广播接收器,但我不确定...?

Sending and Receiving Messages:

You send messages using the MessageApi and attach the following items to the message:

  • An arbitrary payload (optional)
  • A path that uniquely identifies the message's action

3.如果不是,那么在可穿戴应用程序中实现警报是否效率低下或被认为是糟糕的设计?

Scheduling Repeating Alarms:

Alarms (based on the AlarmManager class) give you a way to perform time-based operations outside the lifetime of your application. For example, you could use an alarm to initiate a long-running operation, such as starting a service once a day to download a weather forecast.

注意:试试这个教程:Android Wear Development