记录步数
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您的应用可以使用 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):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eYour app can record cumulative step count data using the RecordingClient and subscribing to the \u003ccode\u003eDataType.TYPE_STEP_COUNT_CUMULATIVE\u003c/code\u003e data type.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Fit persistently stores step data and automatically restores subscriptions, allowing your app to access daily step totals even when not actively running.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the provided code example to learn how to implement step count recording in your application.\u003c/p\u003e\n"]]],[],null,["# Record Steps\n\nYour app can record the user's step count by using the [RecordingClient](/android/reference/com/google/android/gms/fitness/RecordingClient)\nto create a subscription to the `DataType.TYPE_STEP_COUNT_CUMULATIVE` data\ntype, as shown in the following example: \n\n```kotlin\nFitness.getRecordingClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))\n .subscribe(DataType.TYPE_STEP_COUNT_CUMULATIVE)\n .addOnSuccessListener {\n Log.i(TAG,\"Subscription was successful!\")\n }\n .addOnFailureListener { e -\u003e\n Log.w(TAG, \"There was a problem subscribing \", e)\n }\n```\n\nGoogle Fit stores the step data from the subscription even if the app is not\nrunning, and restores the subscription when the system restarts. Your app can\n[read the daily step total](/fit/scenarios/read-daily-step-total)\nfrom the user's fitness history.\n\nFor more information, see [Record Fitness Data](/fit/android/record)."]]