跑步课程导入能力,助力科学训练

HUAWEI Health Kit为开发者提供用户自定义的跑步课程导入接口,便于用户在华为运动健康App和华为智能穿戴设备上查看来自生态应用的训练课表,开启科学、适度的运动训练。

跑步课程导入能力支持生态应用在获取用户的华为帐号授权后,将跑步课程数据写入至华为运动健康App,并在已有的华为智能穿戴设备连接并支持课程导入时,直接将课表推送到设备上,用户可以轻松便捷地投入到科学的跑步课程训练中,提升运动表现。

开发者在使用跑步课程导入功能前,请参见申请Health Kit服务完成以下权限的申请:

跑步课程导入对应的Scope权限:https://www.huawei.com/healthkit/location.write

Health Kit联盟卡片申请的权限名称:健康管理 >计划和任务数据。

具体开发流程如下:

将跑步训练计划导入到华为运动健康App并展示。

若需要进行设备下发,可以通过DeepLink跳转到运动健康App自定义课程的详情页面,并实现跑步课程自动下发到该设备(需要华为智能穿戴设备支持自定义课程,并已与运动健康App绑定)。

说明:当获取华为运动健康App版本号返回的versionCode不低于1300002300 时,可使用DeepLink跳转功能。

示例代码

跑步训练计划导入示例代码。

请求示例

POST
https://health-api.cloud.huawei.com/healthkit/v1/trainingplan/workouts
Content-Type: application/json
Authorization: Bearer ***
x-client-id: ***
x-version: ***
x-caller-trace-id: ***
{
    "name": "01:乳酸阈值课程",
    "description": "总距离:7.02公里;总时间:1:19:00;训练负荷:29.7",
    "actionCombine": [
        {
            "actionList": [
                {
                    "name": "Warm up",
                    "describe": "暖身",
                    "target": {
                        "name": "time",
                        "value": 900.0
                    },
                    "strength": {
                        "name": "pace",
                        "valueH": 614000.0,
                        "valueL": 614000.0
                    }
                }
            ],
            "repeatTimes": 1
        },
        {
            "actionList": [
                {
                    "name": "relax",
                    "describe": "动态伸展",
                    "target": {
                        "name": "time",
                        "value": 300.0
                    }
                }
            ],
            "repeatTimes": 1
        },
        {
            "actionList": [
                {
                    "name": "run",
                    "describe": "跑步训练5分钟",
                    "target": {
                        "name": "time",
                        "value": 300.0
                    },
                    "strength": {
                        "name": "pace",
                        "valueH": 486000.0,
                        "valueL": 486000.0
                    }
                },
                {
                    "name": "have a rest",
                    "describe": "缓走或休息",
                    "target": {
                        "name": "time",
                        "value": 60.0
                    }
                },
                {
                    "name": "relax",
                    "describe": "静态伸展",
                    "target": {
                        "name": "time",
                        "value": 300.0
                    }
                }
            ],
            "repeatTimes": 9
        }
    ]
}

响应示例

HTTP/1.1 200 OK
Content-type: application/json;charset=utf-8
{
    "workoutId": "1669019290232",
    "name": "01:乳酸阈值课程",
    "description": "总距离:7.02公里;总时间:1:19:00;训练负荷:29.7",
    "actionCombine": [
        {
            "repeatTimes": 1,
            "actionList": [
                {
                    "name": "Warm up",
                    "describe": "暖身",
                    "target": {
                        "name": "time",
                        "value": 900.0
                    },
                    "strength": {
                        "name": "pace",
                        "valueH": 614000.0,
                        "valueL": 614000.0
                    }
                }
            ]
        },
        {
            "repeatTimes": 1,
            "actionList": [
                {
                    "name": "relax",
                    "describe": "动态伸展",
                    "target": {
                        "name": "time",
                        "value": 300.0
                    }
                }
            ]
        },
        {
            "repeatTimes": 9,
            "actionList": [
                {
                    "name": "run",
                    "describe": "跑步训练5分钟",
                    "target": {
                        "name": "time",
                        "value": 300.0
                    },
                    "strength": {
                        "name": "pace",
                        "valueH": 486000.0,
                        "valueL": 486000.0
                    }
                },
                {
                    "name": "have a rest",
                    "describe": "缓走或休息",
                    "target": {
                        "name": "time",
                        "value": 60.0
                    }
                },
                {
                    "name": "relax",
                    "describe": "静态伸展",
                    "target": {
                        "name": "time",
                        "value": 300.0
                    }
                }
            ]
        }
    ],
    "createTime": 1669019290232
}

DeepLink跳转运动健康App完成跑步课程自动导入。

参数说明

示例代码

String deeplink="huaweischeme://healthapp/fitnesspage?skip_type=custom_course&id=workoutId&version=2.0";           
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(deeplink));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);

了解更多详情>>

更多相关内容请参见跑步课程导入章节。

如您需要了解更多功能,请访问华为运动健康服务联盟官网

访问HMS Core 联盟官网

获取HMS Core 开发指导文档

关注我们,第一时间了解 HMS Core 最新技术资讯~

热门相关:首席的独宠新娘   重生之至尊千金   名门天后:重生国民千金   无限杀路   名门天后:重生国民千金