android - 我们需要用什么来代替 Android 中的 wear api?

标签 android wear-os android-wear-data-api

Android Wearable.API 已弃用?那么我们需要用什么来构建api客户端。

我现在的代码是

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .build();
        mGoogleApiClient.connect();

//从此 Wearable.API 被弃用。

我已经通过这个链接 https://developers.google.com/android/reference/com/google/android/gms/wearable/Wearable#getDataClient(android.app.Activity,%20com.google.android.gms.wearable.Wearable.WearableOptions)

这里他们要求改成data client和message client。

那么谁能帮我举个例子具体怎么做? 感谢和问候,

更新: 以下是正确的方法吗?

 .addApi(Wearable.getDataClient(MainActivity.this).getApi())
.addApi(Wearable.getMessageClient(MainActivity.this).getApi())

如果是这样,那么 onMessageReceive() 和 onDataChange() 接口(interface)的用途是什么。我的意思是我已经在实现它们。

最佳答案

请在此处查看有关从 GoogleApiClient 迁移到基于 GoogleApi 类的对象的 Google 文档。

https://developer.android.com/training/wearables/data-layer/migrate-to-googleapi

关于android - 我们需要用什么来代替 Android 中的 wear api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50713223/

相关文章:

android - 设置appcompat工具栏菜单字体样式加粗

android - Android Wear 中的 onTouchEvent 覆盖

android - Android wear 模块中的“意外命名空间前缀 "app"”

android - 绑定(bind)到服务与 Intent 基础通信

android - 在 AWS-China 和 AWS-Global 之间更改应用程序中的区域

java - IPackageStatsObserver 无法解析为类型 (Android)

Android Wear 应用程序打包失败

java - Android:如何添加API异常?

android - onDataChanged 监听器未检测到数据传输(Data Api)

java - 将对象从手机共享到 android wear