当前位置:  开发笔记 > Android > 正文

集成S Health SDK

如何解决《集成SHealthSDK》经验,为你挑选了1个好方法。

我使用Samsung S Health SDK开发了我的应用程序.我想在我的应用程序中添加S Health的步行,跑步和骑行跟踪.

如何添加这些功能?



1> Shruti..:

我在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());
    }
}

然后更新了ResultListener:

private final HealthResultHolder.ResultListener mListener = new HealthResultHolder.ResultListener() {
    @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);
    }
};

在HashSet MainActivity中添加了以下权限:

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

并在AndroidManifest文件中:


推荐阅读
臭小子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有