Record Steps

Your app can record the user's step count by using the Recording API to create a subscription to the DataType.TYPE_STEP_COUNT_CUMULATIVE data type, as shown in the following example:

public void subscribe() {
    // To create a subscription, invoke the Recording API. As soon as the subscription is
    // active, fitness data will start recording.
    Fitness.RecordingApi.subscribe(mClient, DataType.TYPE_STEP_COUNT_CUMULATIVE)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    if (status.isSuccess()) {
                        if (status.getStatusCode()
                                == FitnessStatusCodes.SUCCESS_ALREADY_SUBSCRIBED) {
                            Log.i(TAG, "Existing subscription for activity detected.");
                        } else {
                            Log.i(TAG, "Successfully subscribed!");
                        }
                    } else {
                        Log.w(TAG, "There was a problem subscribing.");
                    }
                }
            });
}

Google Fit stores the step data from the subscription even if the app is not running, and restores the subscription when the system restarts. Your app can read the daily step total from the user's fitness history.

For more information, see Record Fitness Data.

发送以下问题的反馈:

此网页
Google Fit
Google Fit