android Wearable-Sending and Syncing Data

本文深入探讨了TheWearableDataLayerAPI在连接手持设备与可穿戴设备间的通信机制,解释了DataItem、Message、Asset、Wearable Listener Service和Data Listener的功能,并详细阐述了Channel API在传输大型数据文件方面的优势。

The Wearable Data Layer API, which is part of Google Play services, provides a communication channel for your handheld and wearable apps. The API consists of a set of data objects that the system can send and synchronize over the wire and listeners that notify your apps of important events with the data layer:

Data Items
DataItem provides data storage with automatic syncing between the handheld and wearable.
Messages
The  MessageApi class can send messages and is good for remote procedure calls (RPC), such as controlling a handheld's media player from the wearable or starting an intent on the wearable from the handheld. Messages are also great for one-way requests or for a request/response communication model. If the handheld and wearable are connected, the system queues the message for delivery and returns a successful result code. If the devices are not connected, an error is returned. A successful result code does not indicate that the message was delivered successfully as the devices may disconnect after receiving the result code.

Asset
Asset objects are for sending binary blobs of data, such as images. You attach assets to data items and the system automatically takes care of the transfer for you, conserving Bluetooth bandwidth by caching large assets to avoid re-transmission.
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.
Channel
You can use the  ChannelApi class to transfer large data items, such as music and movie files, from a handheld to a wearable device. The Channel API for data transfer has the following benefits:
  • Transfer large data files between two or more connected devices, without the automatic synchronization provided when using Asset objects attached to DataItem objects. The Channel API saves disk space unlike the DataApi class, which creates a copy of the assets on the local device before synchronizing with connected devices.
  • Reliably send a file that is too large in size to send using the MessageApi class.
  • Transfer streamed data, such as music pulled from a network server or voice data from the microphone.

Warning: Because these APIs are designed for communication between handhelds and wearables, these are the only APIs you should use to set up communication between these devices. For instance, don't try to open low-level sockets to create a communication channel.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值