记录步数
您的应用可以使用 RecordingClient 记录用户的步数。
创建对 DataType.TYPE_STEP_COUNT_CUMULATIVE
数据的订阅
类型,如以下示例所示:
Fitness.getRecordingClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))
.subscribe(DataType.TYPE_STEP_COUNT_CUMULATIVE)
.addOnSuccessListener {
Log.i(TAG,"Subscription was successful!")
}
.addOnFailureListener { e ->
Log.w(TAG, "There was a problem subscribing ", e)
}
Google 健身会存储来自订阅的步数数据,即使应用未安装在 Google 健身中也是如此。
并在系统重启时恢复订阅。您的应用可以
读取每日总步数
从用户的健身历史记录中提取数据。
如需了解详情,请参阅记录健身数据。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-22。
[null,null,["最后更新时间 (UTC):2024-08-22。"],[[["Your app can record cumulative step count data using the RecordingClient and subscribing to the `DataType.TYPE_STEP_COUNT_CUMULATIVE` data type."],["Google Fit persistently stores step data and automatically restores subscriptions, allowing your app to access daily step totals even when not actively running."],["Refer to the provided code example to learn how to implement step count recording in your application."]]],[]]