記錄步數
應用程式可以使用 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 Fit 會儲存訂閱的步數資料 (即使應用程式並未儲存)
並在系統重新啟動時還原訂閱項目。應用程式可以
讀取每日總步數
從使用者的健身記錄中取得
詳情請參閱「記錄健身資料」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-08-22 (世界標準時間)。
[null,null,["上次更新時間: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."]]],[]]