Fitness.API在谷歌Play中删除服务7.0? [英] Fitness.API removed in Google Play Services 7.0?

查看:197
本文介绍了Fitness.API在谷歌Play中删除服务7.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到谷歌播放服务7.0后,我的 GoogleApiClient code,用于连接到谷歌飞度不再起作用:它说:

  

错误:(87,21)错误:发现addApi没有合​​适的方法(空)   方法Builder.addApi(API,O)不适用   (不能从参数实例化,因为实际的和正式的参数列表的长度不同)   方法Builder.addApi(API)是不适用   (实际参数太虚无法通过方法调用转换转换成API)   其中O是一种类型的变量:   Ø扩展了方法addApi声明HasOptions(API,O)

我在哪里code为建设 GoogleApiClient 是:

  mGoogleApiClient =新GoogleApiClient.Builder(本)
    .addApi(Fitness.API)
    .addScope(新范围(Scopes.FITNESS_ACTIVITY_READ_WRITE))
    .addConnectionCallbacks(本)
    .addOnConnectionFailedListener(本)
    。建立();
 

解决方案

每<一href="http://android-developers.blogspot.com/2015/03/google-play-services-70-places-everyone.html">Google播放服务7.0博客帖子:

  

这是你传递到previous Fitness.API你的 GoogleApiClient 现在已经取代了许多API,配套的谷歌Android的适合原料药的高级别组

     
      
  • SENSORS_API通过<一个访问原始传感器数据href="https://developer.android.com/reference/com/google/android/gms/fitness/SensorsApi.html">SensorsApi
  •   
  • RECORDING_API记录,通过<数据href="https://developer.android.com/reference/com/google/android/gms/fitness/RecordingApi.html">RecordingApi
  •   
  • HISTORY_API用于经由<一个插入,删除,或读取数据href="https://developer.android.com/reference/com/google/android/gms/fitness/HistoryApi.html">HistoryApi
  •   
  • SESSIONS_API通过<常务会议href="https://developer.android.com/reference/com/google/android/gms/fitness/SessionsApi.html">SessionsApi
  •   
  • BLE_API与蓝牙低功耗设备交互通过<一href="https://developer.android.com/reference/com/google/android/gms/fitness/BleApi.html">BleApi
  •   
  • CONFIG_API通过访问自定义数据类型和设置为谷歌飞度<一href="https://developer.android.com/reference/com/google/android/gms/fitness/ConfigApi.html">ConfigApi
  •   

因此​​,你应该更新你的 GoogleApiClient 来增加大家使用适当的API。例如,如果你使用 SensorsApi RecordingApi ,您的code应该像两个:

  mGoogleApiClient =新GoogleApiClient.Builder(本)
    .addApi(Fitness.SENSORS_API)
    .addApi(Fitness.REPORTING_API)
    .addScope(新范围(Scopes.FITNESS_ACTIVITY_READ_WRITE))
    .addConnectionCallbacks(本)
    .addOnConnectionFailedListener(本)
    。建立();
 

注:编译老版本的谷歌Play业务应用程序将继续工作,但不会得到随附分裂的API在谷歌Play业务7.0中提到的同一篇博客文章中存储的好处:

  

这变化显著减少了在后台运行谷歌飞度启用应用程序对内存的需求。像往常一样,应用程序建立在谷歌Play业务previous版本将继续工作,但我们强烈建议您重建你的谷歌飞度启用应用程序来利用这个变化的优势。

After upgrading to Google Play Services 7.0, my GoogleApiClient code for connecting to Google Fit no longer works: it says:

Error:(87, 21) error: no suitable method found for addApi(Void) method Builder.addApi(Api,O) is not applicable (cannot instantiate from arguments because actual and formal argument lists differ in length) method Builder.addApi(Api) is not applicable (actual argument Void cannot be converted to Api by method invocation conversion) where O is a type-variable: O extends HasOptions declared in method addApi(Api,O)

Where my code for building the GoogleApiClient is:

mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addApi(Fitness.API)
    .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();

解决方案

Per the Google Play services 7.0 blog post:

The previous Fitness.API that you passed into your GoogleApiClient has now been replaced with a number of APIs, matching the high level set of Google Fit Android APIs:

  • SENSORS_API to access raw sensor data via SensorsApi
  • RECORDING_API to record data via RecordingApi
  • HISTORY_API for inserting, deleting, or reading data via HistoryApi
  • SESSIONS_API for managing sessions via SessionsApi
  • BLE_API to interact with Bluetooth Low Energy devices via BleApi
  • CONFIG_API to access custom data types and settings for Google Fit via ConfigApi

Therefore you should update your GoogleApiClient to add all of the appropriate APIs you use. For example, if you use both the SensorsApi and the RecordingApi, your code should look like:

mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addApi(Fitness.SENSORS_API)
    .addApi(Fitness.REPORTING_API)
    .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();

Note: apps compiled against older versions of Google Play services will continue to work, but won't get the memory benefit that comes with the split APIs in Google Play services 7.0 as mentioned in the same blog post:

This change significantly reduces the memory requirement for Google Fit enabled apps running in the background. Like always, apps built on previous versions of Google Play services will continue to work, but we strongly suggest you rebuild your Google Fit enabled apps to take advantage of this change.

这篇关于Fitness.API在谷歌Play中删除服务7.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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