2

I have developed my app using Samsung S Health SDK. I want to add walking, running and cycling tracking of S Health inside my app.

How to add these features?

2
  • can you guide me how to develop sample app using S health SDK. if you have any example please share it with me Commented Sep 9, 2018 at 4:15
  • @saikrupa exactly what data you need? they have given sample apps in docs, you can refer. Commented Sep 10, 2018 at 4:40

1 Answer 1

6

I added following properties inside my readTodayWalkingDistance():

private void readTodayWalkingDistance() {
    HealthDataResolver resolver = new HealthDataResolver(mStore, null);

    // Set time range from start time of today to the current time
    long startTime = getStartTimeOfToday();
    long endTime = System.currentTimeMillis();
    Filter filter = Filter.and(Filter.greaterThanEquals(HealthConstants.Exercise.START_TIME, startTime),
            Filter.lessThanEquals(HealthConstants.Exercise.START_TIME, endTime));

    HealthDataResolver.ReadRequest request = new ReadRequest.Builder()
            .setDataType(HealthConstants.Exercise.HEALTH_DATA_TYPE)
            .setProperties(new String[]{
                    HealthConstants.Exercise.EXERCISE_TYPE,
                    HealthConstants.Exercise.DURATION,
                    HealthConstants.Exercise.MAX_SPEED,
                    HealthConstants.Exercise.MEAN_SPEED,
            })
            .setFilter(filter)
            .build();

    try {
        resolver.read(request).setResultListener(mListener);
    } catch (Exception e) {
        Log.e(MainActivity.APP_TAG, e.getClass().getName() + " - " + e.getMessage());
    }
}

Then updated ResultListener:

private final HealthResultHolder.ResultListener<ReadResult> mListener = new HealthResultHolder.ResultListener<ReadResult>() {
    @Override
    public void onResult(ReadResult result) {
        int exercise_type = 0;
        long duration = 0;
        float max_speed = 0.0f, mean_speed = 0.0f;
        Cursor c = null;

        try {
            c = result.getResultCursor();
            if (c != null) {
                while (c.moveToNext()) {

                    exercise_type += c.getInt(c.getColumnIndex(HealthConstants.Exercise.EXERCISE_TYPE));
                    duration += c.getLong(c.getColumnIndex(HealthConstants.Exercise.DURATION));
                    max_speed += c.getColumnIndex(HealthConstants.Exercise.MAX_SPEED);
                    mean_speed += c.getColumnIndex(HealthConstants.Exercise.MEAN_SPEED);
                }
            }
        } finally {
            if (c != null) {
                c.close();
            }
        }
        MainActivity.getInstance().getData(exercise_type, duration, max_speed, mean_speed);
    }
};

Added following permissions in to HashSet MainActivity:

mKeySet.add(new PermissionKey(HealthConstants.Exercise.HEALTH_DATA_TYPE, PermissionType.READ));

And in AndroidManifest file:

<meta-data
    android:name="com.samsung.android.health.permission.read"
    android:value="com.samsung.health.exercise" />
Sign up to request clarification or add additional context in comments.

10 Comments

what did you use for it? Jar file or dependency ?
@AnshulTyagi I used samsung-digital-health-healthdata-1.2.1.jar file
ok. Can you please provide me lil source code or idea how it reads data of S health app for running exercise etc ?
@Shruti how we can fetch all total active mint of day from Samsung health sdk
@Shruti Very helpful -Vote up! ;)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.