- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在开发一款适用于 Android Wear 的应用程序,它可以在手机上启动一项 Activity 。一切都很好,但我不想依赖手机上不断运行的后台服务来接收这条消息。理想情况下,我会让 WearableListenerService 与应用程序同时启动并保持运行直到 onPause。
有没有办法使用广播接收器和 Intent 过滤器拦截来自 Wear 的消息,然后从接收器启动应用程序/服务?下面是一些代码:
向手机发送消息:
private void sendMessage(String path, byte[] data) {
if (mNode != null && mGoogleApiClient!=null && mGoogleApiClient.isConnected()) {
Wearable.MessageApi.sendMessage(
mGoogleApiClient, mNode.getId(), path, data).setResultCallback(
new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
if (!sendMessageResult.getStatus().isSuccess()) {
Log.e("TAG", "Failed to send message with status code: "
+ sendMessageResult.getStatus().getStatusCode());
Toast info = Toast.makeText(WearActivity.this, "Failed to send message, status code: " + sendMessageResult.getStatus().getStatusCode(), Toast.LENGTH_SHORT);
info.show();
}
}
}
);
}
}
在接收端,我有接收消息的 WearableListenerService。 (注意,手机和手机都有 WearableListenerService 类,因此通信是双向的。
最佳答案
根据 Sending an Syncing data training :
WearableListenerService (for services)
Extending WearableListenerService lets you listen for important data layer events in a service. The system manages the lifecycle of the WearableListenerService, binding to the service when it needs to send data items or messages and **unbinding the service when no work is needed.*
DataListener (for foreground activities)
Implementing DataListener in an activity lets you listen for important data layer events when an activity is in the foreground. Using this instead of the WearableListenerService lets you listen for changes only when the user is actively using your app.
如果您只想在 Activity 打开时接收消息(忽略关闭时发送的任何消息),您可以添加 MessageApi.MessageListener到你的 Activity 。
如果您希望无论您的应用程序是否打开都接收消息(确保您不会丢弃从可穿戴设备发送的消息),那么您应该使用 WearableListenerService
(注意:WearableListenerService
不会持续运行 - 它仅在发送新消息/节点连接/数据层更改时启动,并在没有更多消息时停止)。
关于Android Wear - 在没有 WearableListenerService 的情况下接收来自 Wear 的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27130706/
我一直在 list 中使用以下意图过滤器,一切正常: 这已被弃用,所以我尝试使用: 我可以正常接收消息,但 onPeerConnected 现在永远不会被调用。 public class
我一直在 list 中使用以下意图过滤器,一切正常: 这已被弃用,所以我尝试使用: 我可以正常接收消息,但 onPeerConnected 现在永远不会被调用。 public class
最新的Android Wear更新随附对ChannelApi的支持,可用于向可穿戴设备或手持设备发送文件或从可穿戴设备或手持设备发送文件。问题是我找不到有关如何使用此功能的单个示例。 Android示
我已经根据官方 API 更新了我的 Android Wear 表盘,总体来说进展顺利。然而,我坚持的一件事是从 Android Wear 应用程序中启动配套(手持)配置事件。我只是无法在 AW 应用程
我在 Moto 360 上启用了蓝牙调试并在我的 Nexus4 上启用了 Android Wear 应用程序。 状态显示目标:已断开 从我的电脑转发端口显示状态主机将更改为已连接,但目标状态仍保持断开
Android Wear 生态系统似乎是围绕用户将与之交互然后关闭的快速任务构建的。这对大多数应用程序都很有效,但是对于一个涵盖长时间运行的任务并且在 watch 休眠时不应自动关闭的应用程序呢? 我
我正在 Android 中开发一个应用程序以及 Android Wear 支持。在查看来自 https://developer.android.com/training/building-wearab
我打开了 USB 调试,我显示目标已连接,但我无法连接主机。 当我在我的 PC 上运行以下命令时,我得到指示该命令未完成的输出。 adb forward tcp:4444 localabstract:
据我所知,有两种方法可以为 Android Wear 中的通知设置背景图像。为了记录,两者都以: Bitmap bitmap; Notification.Builder bob = new
我正在编写一个自定义 Android Wear 应用程序,该应用程序应该向连接的主机设备(电话)发送一次性消息。通过 API 挖掘,我发现以下教程应该可以很好地工作:http://developer.
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在尝试将文件从我的 Google Wear 发送到我的 Nexus 5。我已经阅读了一些教程并想出了以下代码,但我的手机没有收到文件。 手机: private GoogleApiClient mG
我正在尝试为 Google Wear 设置我的开发环境并遵循了 Google 的 instructions但是一旦我设置了端口转发 (adb -d forward tcp:5601 tcp:5601)
在开发 Android Wear 表盘时,如何检测屏幕是否是圆形且有下巴(又名扁平轮胎带),如 Moto 360?我尝试了 onSurfaceChanged,但宽度和高度是相同的。 我在有下巴的模拟器
我正在为 Android Wear 编写应用程序,我需要在关闭应用程序时实现与 Android Wear 上的 Google map 应用程序类似的行为。 通常,“Swipe-To-Dismiss”手
我正在开发一款适用于 Android Wear 的应用程序,它可以在手机上启动一项 Activity 。一切都很好,但我不想依赖手机上不断运行的后台服务来接收这条消息。理想情况下,我会让 Wearab
我尝试通过启动语音命令启动我的穿戴应用程序。我按照文档 Adding Voice Capabilities .但是,当我尝试通过说(OK Google)“启动我的应用程序”来启动应用程序时,我会收到与
当我使用数字表冠时,我的列表没有滚动 这就是我所做的; public class MainActivity extends Activity { @Override protecte
根据指南: https://developer.android.com/design/wear/patterns.html#Continuing “在必须使用手机的情况下,一旦点击操作按钮并在手机上打
有人可以分享有关使用 Android Wear 使用手腕运动(与触摸屏上的滑动运动相反)进行手势检测的信息吗? API 中有对此的官方支持吗?如果没有,您认为可以通过自定义 ROM 启用此功能吗?考虑
我是一名优秀的程序员,十分优秀!