如何发送和接收消息Android Wear

时间:2015-03-05 17:14:57

标签: android wear-os moto-360

我正在尝试将我的Moto 360中的String发送到Android应用程序!但是我不明白如何在文档中实现代码,任何人都可以帮我解释一下发送数据后要遵循的步骤!

http://developer.android.com/training/wearables/data-layer/messages.html

1 个答案:

答案 0 :(得分:1)

看看样本,这一行准确地显示了如何发送消息:

http://developer.android.com/samples/DataLayer/Application/src/com.example.android.wearable.datalayer/MainActivity.html#l335

private void sendStartActivityMessage(String node) {
    Wearable.MessageApi.sendMessage(
            mGoogleApiClient, node, START_ACTIVITY_PATH, new byte[0]).setResultCallback(
            new ResultCallback<SendMessageResult>() {
                @Override
                public void onResult(SendMessageResult sendMessageResult) {
                    if (!sendMessageResult.getStatus().isSuccess()) {
                        Log.e(TAG, "Failed to send message with status code: "
                                + sendMessageResult.getStatus().getStatusCode());
                    }
                }
            }
    );
}

如果信息太多,MessageApi的简单教程应该只是谷歌搜索。试试这个:http://www.binpress.com/tutorial/a-guide-to-the-android-wear-message-api/152看起来很合理。