### Start Window Configuration Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example JSON configuration for the `startWindow` tag, pointing to a profile file that defines the UIAbility component's startup page. This allows for customization of the application's splash screen. ```json { "startWindowType": "REQUIRED_SHOW", "startWindowAppIcon": "$media:start_window_app_icon", "startWindowIllustration": "$media:start_window_illustration", "startWindowBrandingImage": "$media:start_window_branding_image", "startWindowBackgroundColor": "$color:start_window_back_ground_color", "startWindowBackgroundImage": "$media:start_window_back_ground_image", "startWindowBackgroundImageFit": "Cover" } ``` -------------------------------- ### Pages Configuration Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example of configuring pages and window settings for a module in an OHOS application. ```json { "module": { // ... "pages": "$profile:main_pages" // Configured via resource file under profile } } ``` -------------------------------- ### Pages and Window Configuration Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example of defining page routes and window properties within a profile resource file. ```json { "src": [ "pages/index/mainPage", "pages/second/payment", "pages/third/shopping_cart", "pages/four/owner" ], "window": { "designWidth": 720, "autoDesignWidth": false } } ``` -------------------------------- ### OHOS Ability Configuration Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md An example JSON structure demonstrating the configuration of an OHOS UIAbility component, including various properties like name, source entry, launch type, and window-related settings. ```json { "abilities": [{ "name": "EntryAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "launchType":"singleton", "description": "$string:description_main_ability", "icon": "$media:layered_image", "label": "$string:EntryAbility_label", "permissions": [], "metadata": [], "exported": true, "continuable": true, "skills": [{ "actions": ["ohos.want.action.home"], "entities": ["entity.system.home"], "uris": [] }], "backgroundModes": [ "dataTransfer", "audioPlayback", "audioRecording", "location", "bluetoothInteraction", "multiDeviceConnection", "wifiInteraction", "voip", "taskKeeping" ], "startWindow": "$profile:start_window", "startWindowIcon": "$media:icon", "startWindowBackground": "$color:red", "removeMissionAfterTerminate": true, "orientation": "$string:orientation", "supportWindowMode": ["fullscreen", "split", "floating"], "maxWindowRatio": 3.5, "minWindowRatio": 0.5, "maxWindowWidth": 2560, "minWindowWidth": 1400, "maxWindowHeight": 300, "minWindowHeight": 200, "excludeFromMissions": false, "unclearableMission": false, "excludeFromDock": false, "preferMultiWindowOrientation": "default", "isolationProcess": false, "continueType": [ "continueType1", "continueType2" ], "continueBundleName": [ "com.example.myapplication1", "com.example.myapplication2" ], "process": ":processTag" }] } ``` -------------------------------- ### Shortcuts Configuration Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example of a JSON configuration file for defining application shortcuts, including shortcut ID, label, icon, visibility, and target wants. ```json { "shortcuts": [ { "shortcutId": "id_test1", "label": "$string:shortcut", "icon": "$media:aa_icon", "visible": true, "wants": [ { "bundleName": "com.ohos.hello", "moduleName": "entry", "abilityName": "EntryAbility", "parameters": { "testKey": "testValue" } } ] } ] } ``` -------------------------------- ### DistributionFilter - Device Type Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example demonstrating how different entries in a project can specify device types, requiring distributionFilter for differentiation. ```json { "module": { "name": "entry1", "type": "entry", "deviceTypes" : [ "tv", "tablet" ] } } { "module": { "name": "entry2", "type": "entry", "deviceTypes" : [ "car", "tablet" ] } } ``` -------------------------------- ### Device Types Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example of configuring device types for a module in an OHOS application. ```json { "module": { "name": "myHapName", "type": "feature", "deviceTypes" : [ "tablet" ] } } ``` -------------------------------- ### OpenHarmony Development Paradigms Comparison Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/start-overview.md Compares the declarative development paradigm using ArkTS with the Web-like development paradigm using JS for OpenHarmony applications. It highlights differences in language ecosystem, UI update methods, applicable scenarios, and target developers. ```APIDOC Development Paradigm Comparison: | Development Paradigm Name | Language Ecosystem | UI Update Method | Applicable Scenarios | Target Audience | |---------------------------|--------------------|------------------|----------------------|-----------------| | Declarative (ArkTS) | ArkTS Language | Data-driven | Complex, collaborative | Mobile/System App Developers | | Web-like (JS) | JS Language | Data-driven | Simple UIs, Widgets | Web Frontend Developers | ``` -------------------------------- ### Configure build-profile.json5 for Integrated HSP (Creator Project) Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/integrated-hsp.md This snippet shows how to configure the project-level build-profile.json5 file in the creator project to enable the use of normalized OHM URLs, a prerequisite for Integrated HSP. ```json { "app": { "products": [ { "name": "default", "signingConfig": "default", "compatibleSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", "buildOption": { "strictMode": { "useNormalizedOHMUrl": true } } // ... } ] // ... } } ``` -------------------------------- ### Configure build-profile.json5 for Integrated HSP (User Project) Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/integrated-hsp.md This snippet shows the project-level build-profile.json5 configuration in the user project, ensuring 'useNormalizedOHMUrl' is set to true to utilize the Integrated HSP. ```json { "app": { "products": [ { "name": "default", "signingConfig": "default", "compatibleSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", "buildOption": { "strictMode": { "useNormalizedOHMUrl": true } } } ] } } ``` -------------------------------- ### app.json5 Configuration Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/app-configuration-file.md This snippet shows a typical app.json5 configuration file for an OHOS application. It includes essential fields like bundleName, versionCode, versionName, and various settings for app behavior, environments, and asset access. ```json { "app": { "bundleName": "com.application.myapplication", "vendor": "example", "versionCode": 1000000, "versionName": "1.0.0", "icon": "$media:layered_image", "label": "$string:app_name", "description": "$string:description_application", "minAPIVersion": 9, "targetAPIVersion": 9, "debug": false, "car": { "minAPIVersion": 8 }, "targetBundleName": "com.application.test", "targetPriority": 50, "appEnvironments": [ { "name":"name1", "value": "value1" } ], "maxChildProcess": 5, "multiAppMode": { "multiAppModeType": "multiInstance", "maxCount": 5 }, "hwasanEnabled": false, "ubsanEnabled": false, "cloudFileSyncEnabled": false, "cloudStructuredDataSyncEnabled": false, "configuration": "$profile:configuration", "assetAccessGroups": [ "com.ohos.photos", "com.ohos.screenshot", "com.ohos.note" ], "startMode": "mainTask" } } ``` -------------------------------- ### Wants Tag Configuration Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example of a JSON configuration for the 'wants' tag, specifying target bundle, module, ability, and custom parameters for a shortcut. ```json { "wants": [ { "bundleName": "com.ohos.hello", "moduleName": "entry", "abilityName": "EntryAbility", "parameters": { "testKey": "testValue" } } ] } ``` -------------------------------- ### Metadata Configuration Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example of configuring custom metadata for a module in an OHOS application. ```json { "module": { "metadata": [{ "name": "module_metadata", "value": "a test demo for module metadata", "resource": "$profile:shortcuts_config" }] } } ``` -------------------------------- ### module.json5 Configuration Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md This snippet demonstrates a typical module.json5 configuration file for an OHOS application. It covers essential settings like module name, type, entry points, device compatibility, abilities, permissions, and metadata. ```json { "module": { "name": "entry", "type": "entry", "description": "$string:module_desc", "srcEntry": "./ets/entryability/EntryAbility.ets", "mainElement": "EntryAbility", "deviceTypes": [ "default", "tablet" ], "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", "virtualMachine": "ark", "appStartup": "$profile:app_startup_config", "metadata": [ { "name": "string", "value": "string", "resource": "$profile:distributionFilter_config" } ], "abilities": [ { "name": "EntryAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", "icon": "$media:layered_image", "label": "$string:EntryAbility_label", "startWindow": "$profile:start_window", "startWindowIcon": "$media:icon", "startWindowBackground": "$color:start_window_background", "exported": true, "skills": [ { "entities": [ "entity.system.home" ], "actions": [ "ohos.want.action.home" ] } ], "continueType": [ "continueType1" ], "continueBundleName": [ "com.example.myapplication1", "com.example.myapplication2" ] } ], "definePermissions": [ { "name": "ohos.abilitydemo.permission.PROVIDER", "grantMode": "system_grant", "availableLevel": "system_core", "provisionEnable": true, "distributedSceneEnable": false, "label": "$string:EntryAbility_label" } ], "requestPermissions": [ { "name": "ohos.abilitydemo.permission.PROVIDER", "reason": "$string:reason", "usedScene": { "abilities": [ "FormAbility" ], "when": "inuse" } } ], "querySchemes": [ "app1Scheme", "app2Scheme" ], "routerMap": "$profile:router_map", "appEnvironments": [ { "name": "name1", "value": "value1" } ], "hnpPackages": [ { "package": "hnpsample.hnp", "type": "public" } ], "fileContextMenu": "$profile:menu", "crossAppSharedConfig": "$profile:shared_config" } } ``` -------------------------------- ### Metadata Configuration for Shortcuts Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example of configuring the metadata tag within a module.json5 file to enable shortcut configuration for a UIAbility. ```json { "module": { // ... "abilities": [ { "name": "EntryAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", // ... "skills": [ { "entities": [ "entity.system.home" ], "actions": [ "ohos.want.action.home" ] } ], "metadata": [ { "name": "ohos.ability.shortcuts", "resource": "$profile:shortcuts_config" } ] } ] } } ``` -------------------------------- ### Example Extension Ability Configuration Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md A JSON example demonstrating the structure and values for configuring an extension ability, specifically a 'form' type, including its name, source, icon, label, permissions, URI, skills, metadata, process mode, and data group IDs. ```json { "extensionAbilities": [ { "name": "FormName", "srcEntry": "./form/MyForm.ts", "icon": "$media:icon", "label" : "$string:extension_name", "description": "$string:form_description", "type": "form", "permissions": ["ohos.abilitydemo.permission.PROVIDER"], "readPermission": "", "writePermission": "", "exported": true, "uri":"scheme://authority/path/query", "skills": [ { "actions": [], "entities": [], "uris": [], "permissions": [] } ], "metadata": [ { "name": "ohos.extension.form", "resource": "$profile:form_config" } ], "extensionProcessMode": "instance", "dataGroupIds": [ "testGroupId1" ] } ] } ``` -------------------------------- ### Skills Tag JSON Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md A JSON example demonstrating the structure and usage of the 'skills' tag within an OHOS application's configuration, showcasing how to define actions, entities, URIs, permissions, and domain verification for an ability. ```json { "abilities": [ { "skills": [ { "actions": [ "ohos.want.action.home" ], "entities": [ "entity.system.home" ], "uris": [ { "scheme":"http", "host":"example.com", "port":"80", "path":"path", "type": "text/*", "linkFeature": "Login" } ], "permissions": [], "domainVerify": false } ] } ] } ``` -------------------------------- ### Add Integrated HSP Dependency in User Project Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/integrated-hsp.md This snippet illustrates how to add the Integrated HSP as a dependency in the user project's oh-package.json5 file, referencing the copied .tgz package. ```json { "dependencies": { "hsp": "./libs/library-default.tgz" } } ``` -------------------------------- ### Install and Uninstall Applications using bm tool Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/application-package-install-uninstall.md Developers can install and uninstall applications using the `bm` tool. Refer to the `bm` tool documentation for specific commands and detailed instructions on the build, release, and deployment process. ```APIDOC bm install - Installs an application package. - Parameters: - path_to_hap: The file path to the application's .hap package. bm uninstall - Uninstalls an application. - Parameters: - bundle_name: The unique bundle name of the application to uninstall. ``` -------------------------------- ### OpenHarmony Application Models Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/start-overview.md Describes the two application models provided by OpenHarmony: the Stage model and the FA (Feature Ability) model. The Stage model, introduced with API 9, is the currently recommended and evolving model. The FA model, supported since API 7, is no longer the primary focus. ```APIDOC Application Models: - Stage Model: - Introduced in OpenHarmony API 9. - Currently recommended and actively developed. - Features components like AbilityStage and WindowStage. - Development overview: [Stage Model Development Overview](../application-models/stage-model-development-overview.md) - **This guide uses the Stage model for development instructions.** - FA (Feature Ability) Model: - Supported since OpenHarmony API 7. - No longer the primary focus for new development. - Development overview: [FA Model Development Overview](../application-models/fa-model-development-overview.md) Further differences in architecture and design philosophy can be found in [Understanding Application Models](../application-models/application-models.md). ``` -------------------------------- ### ArkUI Example Reference Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/introduction-to-arkts.md Provides a reference to a complete application example using ArkUI, demonstrating its GUI programming capabilities. It links to a specific section for detailed code examples. ```markdown [MVVM代码示例](../ui/state-management/arkts-mvvm.md#代码示例)提供了一个完整的基于ArkUI的应用程序,以展示其GUI编程功能。 有关ArkUI功能的更多详细信息,请参见ArkUI[基本语法概述](../ui/state-management/arkts-basic-syntax-overview.md)。 ``` -------------------------------- ### File Context Menu Resource File Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example of a `menu.json` resource file used to define the behavior and appearance of custom right-click menu items. It specifies the `abilityName`, `menuItem`, `menuHandler`, and `menuContext` for each menu entry. ```json { "fileContextMenu": [ { "abilityName": "EntryAbility", "menuItem": "$string:module_desc", "menuHandler": "openCompress", "menuContext": [ { "menuKind": 0 }, { "menuKind": 1, "menuRule": "both", "fileSupportType": [ ".rar", ".zip" ], "fileNotSupportType": [ "" ] }, { "menuKind": 2, "menuRule": "single" }, { "menuKind": 3 } ] } ] } ``` -------------------------------- ### Configure Module build-profile.json5 for Integrated HSP (Creator Project) Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/integrated-hsp.md This snippet demonstrates configuring the module-level build-profile.json5 file in the creator project to set the 'integratedHsp' option to true, designating the module as an Integrated HSP. ```json { "apiType": "stageMode", "buildOption": { "arkOptions": { "integratedHsp": true } } } ``` -------------------------------- ### Theme Configuration File (theme_config.json) Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md This example shows the structure of a theme configuration file (theme_config.json) used with the systemTheme tag. It defines the system theme to be used by the application, referencing system-defined themes. ```json { "systemTheme": "$ohos:theme:ohos_theme" } ``` -------------------------------- ### File Context Menu Configuration Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Example JSON configuration for the `fileContextMenu` tag, specifying how to register custom right-click menu items in the file manager. It includes details on ability name, menu item display, handler, and context conditions. ```json { "module": { "fileContextMenu": "$profile:menu" } } ``` -------------------------------- ### Example deviceConfig JSON Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/deviceconfig-structure.md A JSON example demonstrating the structure of the deviceConfig object, including default settings for process, backup, and network security configurations with domain settings. ```json "deviceConfig": { "default": { "process": "com.example.test.example", "supportBackup": false, "network": { "cleartextTraffic": true, "securityConfig": { "domainSettings": { "cleartextPermitted": true, "domains": [ { "subdomains": true, "name": "example.ohos.com" } ] } } } } } ``` -------------------------------- ### testRunner Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-structure.md An example of the testRunner configuration, showing how to specify the name and source path for a test runner. ```json "testRunner": { "name": "myTestRunnerName", "srcPath": "etc/test/TestRunner.ts" } ``` -------------------------------- ### Shortcuts Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-structure.md An example demonstrating the structure of a 'shortcuts' object, including shortcut ID, label, and intents with target bundle and class. ```json "shortcuts": [ { "shortcutId": "id", // $string:shortcut is the configured string resource value "label": "$string:shortcut", "intents": [ { "targetBundle": "com.example.world.test", "targetClass": "com.example.world.test.entry.EntryAbility" } ] } ] ``` -------------------------------- ### App Object Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/app-structure.md A JSON example demonstrating the structure of the app object with sample values for its properties. ```JSON { "app": { "bundleName": "com.example.myapplication", "vendor": "example", "version": { "code": 8, "name": "8.0.1" }, "apiVersion": { "compatible": 8, "target": 9, "releaseType": "Beta1" } } } ``` -------------------------------- ### config.json Structure and Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/application-configuration-file-overview-fa.md This snippet illustrates the structure of the config.json file for OHOS applications in the FA model. It includes the mandatory 'app', 'deviceConfig', and 'module' sections, along with a comprehensive example demonstrating various configuration options for an application's bundle name, version, abilities, device types, and more. ```json { "app": { "vendor": "example", "bundleName": "com.example.demo", "version": { "code": 1000000, "name": "1.0.0" } }, "deviceConfig": { }, "module": { "mainAbility": ".MainAbility_entry", "deviceType": [ "tablet" ], "commonEvents": [ { "name": ".EntryAbility", "permission": "ohos.permission.GET_BUNDLE_INFO", "data": [ "com.example.demo", "100" ], "events": [ "install", "update" ] } ], "abilities": [ { "skills": [ { "entities": [ "entity.system.home" ], "actions": [ "action.system.home" ] } ], "orientation": "unspecified", "visible": true, "srcPath": "MainAbility_entry", "name": ".MainAbility_entry", "srcLanguage": "ets", "icon": "$media:icon", "description": "$string:MainAbility_entry_desc", "formsEnabled": false, "label": "$string:MainAbility_entry_label", "type": "page", "launchType": "multiton" } ], "distro": { "moduleType": "entry", "installationFree": false, "deliveryWithInstall": true, "moduleName": "myapplication" }, "package": "com.example.myapplication", "srcPath": "", "name": ".myapplication", "js": [ { "mode": { "syntax": "ets", "type": "pageAbility" }, "pages": [ "pages/index" ], "name": ".MainAbility_entry", "window": { "designWidth": 720, "autoDesignWidth": false } } ] } } ``` -------------------------------- ### 配置OpenHarmony工程的build-profile.json5 Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/start-with-ets-stage.md 修改工程级build-profile.json5文件以适配OpenHarmony,包括添加compileSdkVersion,设置compatibleSdkVersion和compileSdkVersion为整数,并将runtimeOS从"HarmonyOS"修改为"OpenHarmony"。 ```json { "products": [ { "name": "default", "signingConfig": "default", "compileSdkVersion": 12, // 指定OpenHarmony应用/原子化服务编译时的版本 "compatibleSdkVersion": 12, // 指定OpenHarmony应用/原子化服务兼容的最低版本 "runtimeOS": "OpenHarmony" } ] } ``` -------------------------------- ### Accessing HSP Resources Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/in-app-hsp.md Demonstrates the correct and incorrect ways to access resources within an HSP module using the $r syntax. It highlights the preference for `$r('app.media.example')` over relative paths like `../../resources/base/media/example.png` to avoid incorrect resource referencing. ```ets // library/src/main/ets/pages/Index.ets // Correct usage Image($r('app.media.example')) .id('example') .borderRadius('48px') // Incorrect usage Image("../../resources/base/media/example.png") .id('example') .borderRadius('48px') ``` -------------------------------- ### Java 'this' Binding Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/getting-started-with-arkts-for-java-programmers.md Provides a Java example demonstrating the behavior of the 'this' keyword. In Java, 'this' always refers to the current instance of the class and its binding is determined at compile time by the code structure. ```java class MyClass { void method() { System.out.println(this); // Always refers to the instance of MyClass. } } ``` -------------------------------- ### ArkTS 'this' Binding Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/getting-started-with-arkts-for-java-programmers.md Shows how the 'this' keyword in ArkTS is context-dependent and determined by how a function is called. The example demonstrates scenarios where 'this' binding can change, leading to errors, and how `.bind()` can be used to explicitly set the context. ```typescript class A { bar: string = 'I am A'; foo() { console.info(this.bar); } } class B { bar: string = 'I am B'; callFunction(fn: () => void) { fn(); } } function callFunction(fn: () => void) { fn(); } let a: A = new A(); let b: B = new B(); callFunction(a.foo); // Program crashes. 'this' context has changed. b.callFunction(a.foo); // Program crashes. 'this' context has changed. b.callFunction(a.foo.bind(b)) // Outputs 'I am B'. 'this' context is explicitly set. ``` -------------------------------- ### 配置快捷方式文件 (shortcuts_config.json) Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/typical-scenario-configuration.md 在模块的/resources/base/profile/目录下创建快捷方式配置文件,定义快捷方式的ID、标签、图标以及启动的目标组件和参数。支持通过$string和$media引用资源。 ```json { "shortcuts": [ { "shortcutId": "id_test1", // 标识快捷方式,在应用有多个快捷方式时,该字段可作为快捷方式的唯一标识符,不支持通过资源索引的方式($string)配置该字段 "label": "$string:add", // 标识该快捷方式对外显示的名称 "icon": "$media:add_icon", // 标识该快捷方式对外显示的图片,需要在entry/src/main/resources/base/media中添加名称为add_icon的图片 "wants": [ { "bundleName": "com.ohos.hello", // 对应该快捷方式对应拉起组件的包名 "moduleName": "entry", // 对应该快捷方式对应拉起组件的模块名 "abilityName": "EntryAbility1", // 对应该快捷方式对应拉起组件的组件名 "parameters": { "testKey": "testValue" // 表示拉起快捷方式时的自定义数据 } } ] }, { "shortcutId": "id_test2", // 标识快捷方式,在应用有多个快捷方式时,该字段可作为快捷方式的唯一标识符,不支持通过资源索引的方式($string)配置该字段 "label": "$string:share", // 标识该快捷方式对外显示的名称 "icon": "$media:share_icon", // 标识该快捷方式对外显示的图片,需要在entry/src/main/resources/base/media中添加名称为share_icon的图片 "wants": [ { "bundleName": "com.ohos.hello", // 对应该快捷方式对应拉起组件的包名 "moduleName": "entry", // 对应该快捷方式对应拉起组件的模块名 "abilityName": "EntryAbility", // 对应该快捷方式对应拉起组件的组件名 "parameters": { "testKey": "testValue" // 表示拉起快捷方式时的自定义数据 } } ] } ] } ``` -------------------------------- ### APIDOC: startWindow Tag Configuration Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/module-configuration-file.md Defines the `startWindow` tag used in OHOS profile files to configure the startup page for a UIAbility component. This tag allows customization of the application's splash screen, including icons, illustrations, branding, and background. ```APIDOC startWindow: Description: Points to a profile file resource that specifies the configuration file for the UIAbility component's startup page. If this field is configured, `startWindowIcon` and `startWindowBackground` fields will not take effect. Supports enhanced startup page configuration from API version 20. Attributes: startWindowType: (String, Optional, Default: "REQUIRED_SHOW") Identifies whether the UIAbility component's startup page is hidden. Supported values for 2in1 or tablet free multi-window mode: - "REQUIRED_SHOW": Forces the startup page to display, unaffected by `hideStartWindow` in `StartOptions`. - "REQUIRED_HIDE": Forces the startup page to hide, unaffected by `hideStartWindow` in `StartOptions`. - "OPTIONAL_SHOW": Optionally displays the startup page. Default behavior is to show. Hides if `hideStartWindow` in `StartOptions` is set to hide. startWindowAppIcon: (String, Optional, Max Length: 255) Index of the application icon resource file for the UIAbility component's startup page. startWindowIllustration: (String, Optional, Max Length: 255) Index of the illustration resource file for the UIAbility component's startup page. startWindowBrandingImage: (String, Optional, Max Length: 255) Index of the branding image resource file for the UIAbility component's startup page. startWindowBackgroundColor: (String, Mandatory, Max Length: 255) Index of the background color resource file for the UIAbility component's startup page. startWindowBackgroundImage: (String, Optional, Max Length: 255) Index of the background image resource file for the UIAbility component's startup page. startWindowBackgroundImageFit: (String, Optional, Default: "Cover") Specifies the fitting mode for the UIAbility component's startup page background image. Supported values: - "Contain": Scales the image while maintaining aspect ratio so it fits entirely within the display bounds. - "Cover": Scales the image while maintaining aspect ratio so both sides are greater than or equal to the display bounds. - "Auto": Adaptive display. - "Fill": Scales the image without maintaining aspect ratio to fill the display bounds. - "ScaleDown": Scales the image while maintaining aspect ratio, shrinking or keeping it the same size. - "None": Displays the image in its original size. ``` -------------------------------- ### Run Application on Device Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/start-with-ets-stage.md Instructions on how to initiate the application's execution on the connected development board. This involves using the run button located in the top-right corner of the editor's toolbar. ```APIDOC Toolbar: Location: Top-right corner of the editor window Action: Click the run button (represented by an icon, e.g., ![zh-cn_image_0000001364054485](figures/zh-cn_image_0000001364054485.png)) Result: The application will be deployed and executed on the connected OpenHarmony development board. ``` -------------------------------- ### ArkTS Optional Property Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/getting-started-with-arkts-for-swift-programmers.md Demonstrates the use of optional properties in ArkTS interfaces by appending a question mark ('?') to the property name ('age?'), indicating it can be null or undefined. ```typescript interface Person { name: string; age?: number; // age是可选属性。 } const person: Person = { name: "Alice", }; ``` -------------------------------- ### Swift Class Method 'self' Binding Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/getting-started-with-arkts-for-swift-programmers.md Provides a Swift example demonstrating that 'self' within a class method always refers to the instance of the class, with its binding fixed at compile time. ```swift class MyClass { func method() { print(self) // 始终指向MyClass的实例。 } } ``` -------------------------------- ### ArkTS: 使用工厂函数替代构造函数签名 Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/arkts-more-cases.md 当需要传递一个构造函数作为参数时,可以使用工厂函数(() => Instance)来替代构造函数签名,以简化类型定义。 ```typescript class Controller { value: string = '' constructor(value: string) { this.value = value; } } type ControllerConstructor = () => Controller; class Menu { controller: ControllerConstructor = () => { return new Controller('abc'); } createController() { if (this.controller) { return this.controller(); } return null; } } let t: Menu = new Menu(); console.log(t.createController()!.value); ``` -------------------------------- ### ArkTS Union Type Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/getting-started-with-arkts-for-swift-programmers.md Shows the usage of union types in ArkTS, denoted by the pipe symbol ('|'), allowing a variable ('value') to hold values of either 'string' or 'number' type. ```typescript // 联合类型示例。 let value: string | number; value = 'hello'; value = 123; ``` -------------------------------- ### ArkTS Type Inference Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/getting-started-with-arkts-for-swift-programmers.md Illustrates ArkTS's strong type inference capabilities, where the compiler automatically deduces the type of a variable ('num' as 'number') without explicit type annotation. ```typescript let num = 10; // 编译器自动推断num为number类型。 ``` -------------------------------- ### ArkTS Module Import Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/getting-started-with-arkts-for-java-programmers.md Shows how to import functionalities from the ArkTS standard library, specifically the collections module, using the import statement. This highlights ArkTS's module system for managing dependencies. ```typescript // Import the ArkTS collections from the ArkTS standard library. import { collections } from '@kit.ArkTS'; ``` -------------------------------- ### 在module.json5中引用快捷方式配置 Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/typical-scenario-configuration.md 在应用的module.json5文件的abilities部分,通过metadata配置项指定快捷方式的名称(固定为'ohos.ability.shortcuts')和资源位置(指向shortcuts_config.json文件)。 ```json { "module": { // ... "abilities": [ { "name": "EntryAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", // ... "metadata": [ { "name": "ohos.ability.shortcuts", // 配置快捷方式,该值固定为ohos.ability.shortcuts "resource": "$profile:shortcuts_config" // 指定shortcuts信息的资源位置 } ] } ] } } ``` -------------------------------- ### FA Model Application Package Structure Overview Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/application-package-structure-fa.md Provides a high-level overview of the file and directory structure for applications developed using the FA model in OHOS. It highlights the main components and their purposes. ```markdown # FA模型应用程序包结构 基于[FA模型](application-configuration-file-overview-fa.md)开发的应用,其应用程序包结构如下图应用程序包结构(FA模型)所示。开发者需要熟悉应用程序包结构相关的基本概念。 > **说明:** > API version 8及更早的版本支持的应用模型,FA模型已经不再主推。建议使用新的Stage模型进行开发。 FA模型与Stage模型的主要区别在于HAP内部文件的存放位置不同。FA模型中,所有资源文件、库文件和代码文件都存放在assets文件夹中,并在文件夹内部进一步区分。 - config.json是应用配置文件,DevEco Studio会自动生成部分模块代码,开发者按需修改其中的配置。详细字段请参见[应用配置文件](application-configuration-file-overview-fa.md#配置文件的内部结构)。 - assets是HAP所有的资源文件、库文件和代码文件的集合,内部可以分为entry和js文件夹。entry文件夹中存放的是resources目录和resources.index文件。 - resources目录用于存放应用的资源文件(字符串、图片等),便于开发者使用和维护,详见[资源文件的使用](resource-categories-and-access.md)。 - resources.index是资源索引表,由DevEco Studio调用SDK工具生成。 - js文件夹中存放的是编译后的代码文件。 - `pack.info` 是 Bundle 中用于描述每个 HAP 属性的文件,包含应用的 `bundleName` 和 `versionCode` 信息、模块的 `name`、`type` 和 `abilities` 等信息。该文件由 DevEco Studio 工具在构建 Bundle 包时自动生成。 **图1** 应用程序包结构(FA模型) ![app-pack-fa](figures/app-pack-fa.png) ``` -------------------------------- ### OHOS Project Configuration Files Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/application-package-structure-stage.md Details the primary configuration files for OHOS applications and modules. `app.json5` defines global application settings, while `module.json5` specifies module-level information, permissions, and device support. `build-profile.json5` manages build settings and signing, `hvigorfile.ts` controls build tasks, `obfuscation-rules.txt` handles code obfuscation, and `oh-package.json5` lists dependencies. ```APIDOC app.json5: Description: Application-level configuration file. Declares global application information such as Bundle name, application name, icon, and version. Location: AppScope/app.json5 Related: module.json5, pack.info module.json5: Description: Module-level configuration file. Declares module basic information, supported device types, component information, and required permissions. Location: ModuleName/src/main/module.json5 Related: app.json5, pack.info build-profile.json5: Description: Project-level or Module-level build configuration file. Includes application signing and product configuration. Location: build-profile.json5 (project root or module root) Related: Signing documentation, hvigorfile.ts hvigorfile.ts: Description: Project-level or Module-level build task script. Allows customization of build tool versions and configuration parameters. Location: hvigorfile.ts (project root or module root) Related: build-profile.json5 obfuscation-rules.txt: Description: Obfuscation rules file. Used during Release mode compilation to obfuscate and compress code for asset protection. Location: obfuscation-rules.txt Related: Build modes oh-package.json5: Description: File for storing dependency information, including third-party libraries and shared packages. Location: oh-package.json5 Related: Dependency management ``` -------------------------------- ### ArkTS Optional Types Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/getting-started-with-arkts-for-java-programmers.md Illustrates the use of optional types in ArkTS, denoted by a question mark ('?'). This feature allows properties or parameters to be `null` or `undefined`, providing flexibility in defining data structures and function signatures. ```typescript interface Person { name: string; age?: number; // age is an optional property. } const person: Person = { name: "Alice", }; ``` -------------------------------- ### ArkTS Type Inference Example Source: https://github.com/chenqinggang001/ohos-quick-start/blob/main/getting-started-with-arkts-for-java-programmers.md Demonstrates ArkTS's type inference capability, where the compiler automatically deduces the type of a variable from its assigned value. This reduces the need for explicit type declarations, making the code more concise. ```typescript let num = 10; // Compiler automatically infers num as type number. ```