Android 访问可穿戴数据层
访问可穿戴数据层
编写:wly2014 - 原文: http://developer.android.com/training/wearables/data-layer/accessing.html
调用数据层API,需创建一个 GoogleApiClient 实例,所有 Google Play services APIs的主要入口点。
GoogleApiClient 提供了一个易于创建客户端实例的builder。最简单的GoogleApiClient如下:
Note: 目前,此小client仅足以能启动。但是,更多创建GoogleApiClient,实现回调方法和处理错误等内容,详见 Accessing Google Play services APIs。
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(new ConnectionCallbacks() {
@Override
public void onConnected(Bundle connectionHint) {
Log.d(TAG, "onConnected: " + connectionHint);
// Now you can use the Data Layer API
}
@Override
public void onConnectionSuspended(int cause) {
Log.d(TAG, "onConnectionSuspended: " + cause);
}
})
.addOnConnectionFailedListener(new OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.d(TAG, "onConnectionFailed: " + result);
}
})
// Request access only to the Wearable API
.addApi(Wearable.API)
.build();
Important: 如果我们添加多个API到一个GoogleApiClient,那么可能会在没有安装Android Wear app 的设备上遇到连接错误。为了连接错误,调用
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定