如何通过手持设备在可穿戴设备上启动服务(对光数据进行采样)? [英] How to start a Service (that samples light data) on a wearable from a handheld device?

查看:86
本文介绍了如何通过手持设备在可穿戴设备上启动服务(对光数据进行采样)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Android开发还很陌生,目前正在尝试可穿戴应用。

I am pretty new to Android Development and I am currently experimenting with wearable apps.

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

I created a background Service on my smartwatch that samples light sensor data and I want it to start at a certain time everyday. My current approach is to implement an alarm manager on my handheld device to trigger said service on the watch, but I'm not sure how to make this connection between the phone and watch.

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

From what I have researched I'm not sure if this is even possible. I guess my main questions are:


  1. 是否可以使用在我的电话
    中实现的警报管理器来启动手表上有服务吗? (我希望将来使开始时间用户可配置,因此,理想情况下,希望可以在电话上完成!)

  2. 如果可以,该怎么办?我有一个提示,可以使用messageApi或广播接收器,尽管我不确定...?

  3. 如果没有,发出警报是否效率低下或被认为是不良设计而是在可穿戴应用中实施?

任何帮助将不胜感激!

推荐答案

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

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

Haven't tried it but try checking the Building Apps for Wearables documentation it will teach you how to build notifications in a handheld app that are automatically synced to wearables as well as how to build apps that run on wearables.

2. 如果是,该怎么做?我不确定正在使用messageApi或广播接收器,虽然我不确定...?

发送和接收消息


您使用 MessageApi发送消息并在邮件中附加以下项目:

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


  • 任意有效载荷(可选)

  • 唯一标识邮件操作的路径






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

安排重复警报的时间


警报(基于 AlarmManager 类)为您提供了一种执行时间的方法应用程序生命周期之外的基于操作的操作。例如,您可以使用警报来启动长时间运行的操作,例如每天启动一次服务以下载天气预报。

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开发

这篇关于如何通过手持设备在可穿戴设备上启动服务(对光数据进行采样)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆