gpt4 book ai didi

android - 集成 S 健康 SDK

转载 作者:太空狗 更新时间:2023-10-29 16:12:31 28 4
gpt4 key购买 nike

我使用 Samsung S Health SDK 开发了我的应用程序。我想在我的应用程序中添加 S 健康的步行、运行和骑自行车跟踪。

如何添加这些功能?

最佳答案

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

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

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

在 AndroidManifest 文件中:

<meta-data
android:name="com.samsung.android.health.permission.read"
android:value="com.samsung.health.exercise" />

关于android - 集成 S 健康 SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41690330/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com