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 最新技術資訊~