如何让可穿戴的Android应用在手持设备上触发闹钟? [英] How can I make a wearable Android app set off the alarm on the handheld?

查看:53
本文介绍了如何让可穿戴的Android应用在手持设备上触发闹钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为使用加速度计传感器的手表创建了一个非常简单的安卓可穿戴应用.我将手表通过蓝牙连接到移动设备.当加速度计检测到某个值时,我希望手机发出警报.我对 Android 编程很陌生,但我一直在尝试阅读文档.我正在查看通知文档,但似乎无法弄清楚我需要哪个数据层功能.我想要完成的事情对我来说似乎很简单:在手表上运行应用程序,检测一个值,在手持设备上发出警报.该文档提出了一个更复杂的过程.我是不是想多了?

I created a very simple android wearable app for a watch that uses the accelerometer sensor. I have the watch connected to a mobile device over bluetooth. When a certain value is detected by the accelerometer, I'd like for the phone to sound an alarm. I'm quite new to Android Programming, but I've been trying to read the documentation. I was looking at the Notification documentation, but I can't seem to figure out which data layer functionality I need. What I am trying to accomplish seems very simple to me: Run the app on the watch, detect a value, sound alarm on handheld. The documentation is suggesting a more complicated process. Am I overthinking this?

推荐答案

在穿戴端检测到您感兴趣的事件后,您需要向您的手机应用发送一条消息(使用 MessageApi) 然后你需要实现 WearableListenerService 在可以捕获该消息的手机应用上并触发您感兴趣的任何事情.

Once you detect the event you are interested in on the wear side, you need to send a message to your phone app (using MessageApi) and then you need to have an implementation of WearableListenerService on your phone app that can capture that message and trigger whatever you are interested in.

要向您的手机发送消息,您应该使用 CapabilityApi;基本上你的手机应用程序应该声明它提供alarm_capability"(或任何你想叫它的名字),然后你的穿戴在检测到适当的事件时,可以向框架询问提供alarm_capability"的连接节点.框架将返回与您的手机对应的节点,然后您可以简单地使用 MessageApi 向该节点发送消息.

To send a message to your phone, you should use the CapabilityApi; basically your phone app should declare that it provides, say, "alarm_capability" (or whatever you want to call it) and then your wear, upon detecting the appropriate event, can ask the framework for the connected nodes that provide "alarm_capability". Framework will return the node corresponding to your phone and then you can simply use the MessageApi to send a message to that node.

所有这些都非常简单,我们的 GitHub 存储库上有许多示例,它们实现了类似的功能事情(例如,FindMyPhone 非常接近您想要的).您可以查看这些示例并阅读 API 并尝试一下.另一种方法是使用可简化这些步骤的库,例如您可以使用 WearCompanionLibrary.

All of this is pretty straightforward to do and there are a number of samples on our GitHub repo that accomplish similar things (for example, FindMyPhone is pretty close to what you want). You can look a those samples and also read bout the APIs and give it a try. An alternate approach is to use a library that simplifies these steps, for example you can use WearCompanionLibrary.

这篇关于如何让可穿戴的Android应用在手持设备上触发闹钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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