发送数据,并等待与可穿戴数据层API的答案 [英] Send data and wait for the answers with the Wearable Data Layer API

查看:222
本文介绍了发送数据,并等待与可穿戴数据层API的答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从该数据发送到包裹在一个数据映射对象的手持式装置的可佩戴装置。在手持设备上,我实现了一个扩展侦听器服务 WearableListenerService 以这种方式实现的:

I have a wearable device from which data is sent to a handheld device wrapped in a DataMap object. On the handheld device I implemented a listener service that extends WearableListenerService implemented in this way:

public class ListenerService extends WearableListenerService {
    private static final String TAG = ListenerService.class.toString();

    private static final String WEARABLE_DATA_PATH = "/wearable_data";

    @Override
    public void onDataChanged(DataEventBuffer dataEvents) {
        DataMap dataMap;

        for (DataEvent event : dataEvents) {
            if (event.getType() == DataEvent.TYPE_CHANGED) {
                String path = event.getDataItem().getUri().getPath();

                if (path.equals(WEARABLE_DATA_PATH)) {
                    dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

                    messageReceived(dataMap);
                }
            }
        }
    }

    private void messageReceived(DataMap dataMap) {
        Log.v(TAG, "DataMap received on handheld device: " + dataMap);
    }
}

从穿戴到手持设备传输完美的作品。不过,我需要从掌上电脑发送回耐磨的答案的,像OK完成或错误XXX。我该怎么做?

The transmission from wearable to handheld works flawlessly. However, I would need to send back from handheld to wearable an answer, like "ok done" or "error xxx". How can I do that?

推荐答案

它的工作方式相同。您需要 WearableListenerService 对你的穿戴式应用的子类,宣称它在你的Andr​​oidManifest.xml中,用行动 com.google.android.gms.wearable .BIND_LISTENER 。当手持准备将消息发送到穿戴,你可以使用 DataApi MessageApi 和相应的回调将在其它端点调用

it works the same way. You need a subclass of WearableListenerService on your wearable app, declared it on your AndroidManifest.xml, with the action com.google.android.gms.wearable.BIND_LISTENER. When the handheld is ready send a Message to the Wearable, you can use either the DataApi or the MessageApi and corresponding callback will be invoked on the other endpoint

这篇关于发送数据,并等待与可穿戴数据层API的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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