安装软件
参考HUAWEI DevEco Studio – HarmonyOS应用开发官网,随后根据个人喜好进行个性化设置
注册登录
注册华为开发者账号,并进行实名认证,在软件中登录,登录成功后如下:
HelloWorld
HelloWorld代码不需要写,创建的时候就已经写好,我们重点要知道项目的目录结构,以及如何运行项目
目录结构及其内容
运行项目
启动虚拟机随后单击如下位置的运行按钮即可
运行效果页面的包含关系
页面Ability,子页面AbilitySlice,也叫切片或者片段,随后才是内容
包含关系:
最外面是: Ability
Ability中是一-个或多个子页面: AbilitySlice
子页面中有要展示的内容:图片,文本等信息
配置文件
- {
- "app": {
- "bundleName": "top.zhmq.myapplication",
- "vendor": "zhmq",
- "version": {
- "code": 1000000,
- "name": "1.0.0"
- }
- },
- "deviceConfig": {},
- "module": {
- "package": "top.zhmq.myapplication",
- "name": ".MyApplication",
- "mainAbility": "top.zhmq.myapplication.MainAbility",
- "deviceType": [
- "phone"
- ],
- "distro": {
- "deliveryWithInstall": true,
- "moduleName": "entry",
- "moduleType": "entry",
- "installationFree": false
- },
- "abilities": [
- {
- "skills": [
- {
- "entities": [
- "entity.system.home"
- ],
- "actions": [
- "action.system.home"
- ]
- }
- ],
- "orientation": "unspecified",
- "name": "top.zhmq.myapplication.MainAbility",
- "icon": "$media:icon",
- "description": "$string:mainability_description",
- "label": "$string:entry_MainAbility",
- "type": "page",
- "launchType": "standard"
- }
- ]
- }
- }
项目的配置
app
厂商信息
项目的版本号
代码中的配置
module
比如:
所有的Ability
应用在设备上的配置信息
deviceConfig
比如:
应用运行时进程名
是否允许使用流量
是否支持未解锁时启动
启动流程
- 解析config.json文件
- 初始化
- 获取入口Ability的全类名
- 找到Ability,井运行
- 运行Ability中的子界面
- 加载xml文件,展示内容
相关核心代码,及其位置
- "module": {
- "package": "top.zhmq.myapplication",
- "name": ".MyApplication",
- "mainAbility": "top.zhmq.myapplication.MainAbility",
- public class MyApplication extends AbilityPackage {
- @Override
- public void onInitialize() {
- super.onInitialize();
- }
- }
- public class MainAbility extends Ability {
- @Override
- public void onStart(Intent intent) {
- super.onStart(intent);
- super.setMainRoute(MainAbilitySlice.class.getName());
- }
- }
- public class MainAbilitySlice extends AbilitySlice {
- @Override
- public void onStart(Intent intent) {
- super.onStart(intent);
- super.setUIContent(ResourceTable.Layout_ability_main);
- }
-
- @Override
- public void onActive() {
- super.onActive();
- }
-
- @Override
- public void onForeground(Intent intent) {
- super.onForeground(intent);
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <DirectionalLayout
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:height="match_parent"
- ohos:width="match_parent"
- ohos:alignment="center"
- ohos:orientation="vertical">
-
- <Text
- ohos:id="$+id:text_helloworld"
- ohos:height="match_content"
- ohos:width="match_content"
- ohos:background_element="$graphic:background_ability_main"
- ohos:layout_alignment="horizontal_center"
- ohos:text="$string:mainability_HelloWorld"
- ohos:text_size="40vp"
- />
-
- </DirectionalLayout>
- {
- "string": [
- {
- "name": "entry_MainAbility",
- "value": "entry_MainAbility"
- },
- {
- "name": "mainability_description",
- "value": "Java_Empty Ability"
- },
- {
- "name": "mainability_HelloWorld",
- "value": "你好,世界"
- }
- ]
- }