Ghi lại các bước
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Ứng dụng của bạn có thể ghi lại số bước của người dùng bằng cách sử dụng RecordingClient
để tạo một gói thuê bao cho dữ liệu DataType.TYPE_STEP_COUNT_CUMULATIVE
như trong ví dụ sau:
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 Fit lưu trữ dữ liệu bước đi từ gói thuê bao ngay cả khi ứng dụng không
của bạn đang chạy và khôi phục gói thuê bao khi hệ thống khởi động lại. Ứng dụng của bạn có thể
đọc tổng số bước hằng ngày
từ lịch sử thể dục của người dùng.
Để biết thêm thông tin, hãy xem phần Ghi lại dữ liệu thể chất.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\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)."]]