gpt4 book ai didi

Flutter - Health 包未加载 STEP 数据

转载 作者:行者123 更新时间:2023-12-04 15:04:56 28 4
gpt4 key购买 nike

我在我的 flutter 应用程序中使用了 health-3.0.3 来获取 Google 拟合数据。我能够获得除 STEP 数据以外的所有数据,这些数据始终显示为零。
你可以引用这里的健康包
Health 3.0.3 Flutter
这是在我的应用程序中访问 STEP 数据类型的代码块

List<HealthDataType> types = [
HealthDataType.STEPS,
HealthDataType.WEIGHT,
//HealthDataType.HEIGHT,
];

setState(() => _state = AppState.FETCHING_DATA);

/// You MUST request access to the data types before reading them
bool accessWasGranted = await health.requestAuthorization(types);

double steps = 0;

if (accessWasGranted) {
try {
/// Fetch new data
List<HealthDataPoint> healthData =
await health.getHealthDataFromTypes(startDate, endDate, types);

/// Save all the new data points
_healthDataList.addAll(healthData);
} catch (e) {
print("Caught exception in getHealthDataFromTypes: $e");
}

/// Filter out duplicates
_healthDataList = HealthFactory.removeDuplicates(_healthDataList);

/// Print the results
_healthDataList.forEach((x) {
print("Data point: $x");
steps += (x.value as double);
});

print("Steps: $steps");
您可以引用给定链接中示例选项卡下的完整代码。有谁知道这里有什么问题?

最佳答案

健康:3.0.4 更稳定,当我写这个答案时。
从 Android 10. 你必须添加 ACTIVITY_RECOGNITION用于在 AndroidManifest.xml 中获得 STEP Count 权限.

<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
然后使用 permission_handler请求许可。
if (Platform.isAndroid) {
final permissionStatus = Permission.activityRecognition.request();
if (await permissionStatus.isDenied ||
await permissionStatus.isPermanentlyDenied) {
showToast(
'activityRecognition permission required to fetch your steps count');
return;
}
}

关于Flutter - Health 包未加载 STEP 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66344222/

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