com.google.android.gms.fitness.request.SessionReadRequest

Here are the examples of the java api class com.google.android.gms.fitness.request.SessionReadRequest taken from open source projects.

1. MainActivity#readSession()

View license
@OnClick(R.id.btn_read_session)
public void readSession() {
    if (!mGoogleApiClient.isConnected()) {
        Toast.makeText(this, "Not connected to Google", Toast.LENGTH_SHORT).show();
        return;
    }
    Calendar cal = Calendar.getInstance();
    Date now = new Date();
    cal.setTime(now);
    long endTime = cal.getTimeInMillis();
    cal.add(Calendar.MONTH, -1);
    long startTime = cal.getTimeInMillis();
    SessionReadRequest readRequest = new SessionReadRequest.Builder().setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS).read(DataType.TYPE_SPEED).setSessionName(SESSION_NAME).build();
    PendingResult<SessionReadResult> sessionReadResult = Fitness.SessionsApi.readSession(mGoogleApiClient, readRequest);
    sessionReadResult.setResultCallback(new ResultCallback<SessionReadResult>() {

        @Override
        public void onResult(SessionReadResult sessionReadResult) {
            if (sessionReadResult.getStatus().isSuccess()) {
                Log.i("Tuts+", "Successfully read session data");
                for (Session session : sessionReadResult.getSessions()) {
                    Log.i("Tuts+", "Session name: " + session.getName());
                    for (DataSet dataSet : sessionReadResult.getDataSet(session)) {
                        for (DataPoint dataPoint : dataSet.getDataPoints()) {
                            Log.i("Tuts+", "Speed: " + dataPoint.getValue(Field.FIELD_SPEED));
                        }
                    }
                }
            } else {
                Log.i("Tuts+", "Failed to read session data");
            }
        }
    });
}