乐趣区

关于android:跑步课程导入能力助力科学训练

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 最新技术资讯~

退出移动版