目前鸿蒙官网上的学习代码均是API12的:https://developer.huawei.com/consumer/cn/codelabsPortal/serviceTypes
但是我的Matepad SE 2024只能连接旧版本的DevEcoStudio4.0.0.600,对应的为API9
这样如果想运行示例程序,就必须要更改API版本,在文件build-profile.json5中:
{"app": {"signingConfigs": [],"products": [{"name": "default","signingConfig": "default","compatibleSdkVersion": "5.0.0(12)","runtimeOS": "HarmonyOS"}]},...
}
改为↓↓↓↓↓↓↓↓
{"app": {"signingConfigs": [],"compileSdkVersion": 9,"compatibleSdkVersion": 9,"products": [{"name": "default","signingConfig": "default",}],"buildModeSet": [{"name": "debug",},{"name": "release"}]},...
}
与此同时,我需要使用网络,还要在module.json5中添加如下内容:
(注意:Page的入口也是在这个文件呦)
{"module": {...// 添加如下内容"requestPermissions": [{"name": "ohos.permission.INTERNET","usedScene": {"abilities": ["EntryAbility"],"when": "inuse"},"reason": "$string:reason"}]}
}
常用模块对应关系如下:
------------------------------------------------------------
import { resourceManager } from '@ohos.LocalizationKit';
// ↓↓↓↓↓↓↓↓
import resourceManager from '@ohos.resourceManager';------------------------------------------------------------
import { image } from '@kit.ImageKit';
// ↓↓↓↓↓↓↓↓
import image from '@ohos.multimedia.image';------------------------------------------------------------
import { media } from '@kit.MediaKit';
// ↓↓↓↓↓↓↓↓
import media from '@ohos.multimedia.media';------------------------------------------------------------
import { window } from '@kit.ArkUI';
// ↓↓↓↓↓↓↓↓
import window from '@ohos.window';------------------------------------------------------------
import { promptAction } from '@kit.ArkUI';
// ↓↓↓↓↓↓↓↓
import promptAction from '@ohos.promptAction';------------------------------------------------------------
import { hilog } from '@kit.PerformanceAnalysisKit';
// ↓↓↓↓↓↓↓↓
import hilog from '@ohos.hilog';------------------------------------------------------------
import { UIAbility } from '@kit.AbilityKit';
// ↓↓↓↓↓↓↓↓
import UIAbility from '@ohos.app.ability.UIAbility'------------------------------------------------------------
import { router } from '@kit.ArkUI';
// ↓↓↓↓↓↓↓↓
import router from '@ohos.router';
这样就可以开始学习HarmonyOS SDK啦!