### Example OHOS Module Configuration (JSON) Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md A JSON example demonstrating the configuration of device types within an OHOS module. ```json { "module": { "name": "myHapName", "type": "feature", "deviceTypes" : [ "tablet" ] } } ``` -------------------------------- ### Example OHOS Pages Configuration (JSON) Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md A JSON example illustrating the configuration of pages and window settings for an OHOS module, including page routes and design width. ```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-dev/blob/main/module-configuration-file.md A JSON example demonstrating the structure and values for configuring an OHOS UIAbility component, including various properties like name, source entry, launch type, and specific configurations for window management, mission handling, and multi-window behavior. ```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" } ] } ``` -------------------------------- ### Start Window Tag Attributes Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md Details the attributes for the `startWindow` tag, used to configure the startup page of a UIAbility component. ```APIDOC startWindow: startWindowType: string (Optional, default: "REQUIRED_SHOW") - Specifies whether to hide the startup page. Supported values: "REQUIRED_SHOW": Force display, unaffected by StartOptions hideStartWindow. "REQUIRED_HIDE": Force hide, unaffected by StartOptions hideStartWindow. "OPTIONAL_SHOW": Optional display; defaults to show, hides if StartOptions hideStartWindow is set. startWindowAppIcon: string (Optional) - Index of the startup page icon resource file (max 255 characters). startWindowIllustration: string (Optional) - Index of the startup page illustration resource file (max 255 characters). startWindowBrandingImage: string (Optional) - Index of the startup page branding image resource file (max 255 characters). startWindowBackgroundColor: string (Required) - Index of the startup page background color resource file (max 255 characters). startWindowBackgroundImage: string (Optional) - Index of the startup page background image resource file (max 255 characters). startWindowBackgroundImageFit: string (Optional, default: "Cover") - Specifies how the startup page background image fits the display. Supported values: Contain: Displays the image completely within the bounds, maintaining aspect ratio. Cover: Fills the bounds, maintaining aspect ratio. Auto: Auto-adaptive display. Fill: Fills the bounds without maintaining aspect ratio. ScaleDown: Displays with aspect ratio, shrinking or staying the same. None: Displays in original size. ``` -------------------------------- ### OHOS Skills Tag Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md A JSON example demonstrating the structure and usage of the 'skills' tag within an OHOS application's configuration. It shows how to define actions, entities, URIs with specific schemes and hosts, permissions, and domain verification. ```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 } ] } ] } ``` -------------------------------- ### Example Extension Ability Configuration Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md A JSON example demonstrating the configuration of an Extension Ability, specifically a 'form' type, including its name, source entry, icon, label, permissions, URI, skills, metadata, and process mode. ```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" ] } ] } ``` -------------------------------- ### Example OHOS Metadata Configuration (JSON) Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md A JSON example showing how to configure custom metadata for an OHOS module, including name, value, and resource references. ```json { "module": { "metadata": [{ "name": "module_metadata", "value": "a test demo for module metadata", "resource": "$profile:shortcuts_config" }] } } ``` -------------------------------- ### Start Window Parameter Passing Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md Describes the parameters passed in the `want` object when a right-click menu item is clicked, triggering an application launch. ```APIDOC want.parameter: menuHandler: string - The value of `menuHandler` from the configuration file. uriList: string[] - The URI(s) of the file(s) on which the right-click was triggered. Empty if triggered on a blank area, contains one URI for a single file, or multiple URIs for multiple files. ``` -------------------------------- ### Install Application using bm tool Source: https://github.com/chenqinggang001/ohos-dev/blob/main/application-package-install-uninstall.md Developers can install applications using the 'bm install' command. Refer to the bm tool documentation for detailed usage. ```APIDOC bm install Parameters: : The file path to the .hap application package. ``` -------------------------------- ### OHOS Module Configuration Example Source: https://github.com/chenqinggang001/ohos-dev/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 type, entry points, device compatibility, abilities, permissions, and more. ```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" } } ``` -------------------------------- ### Start Window Configuration Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md 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. ```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" } ``` -------------------------------- ### Instantiating Classes in ArkTS Source: https://github.com/chenqinggang001/ohos-dev/blob/main/arkts-more-cases.md This example addresses a common pattern in ArkTS where classes are used to create instances. It demonstrates how to correctly instantiate classes and manage constructor types, contrasting an older approach with a recommended one. ```arkts class Controller { value: string = '' constructor(value: string) { this.value = value } } interface ControllerConstructor { new (value: string): Controller; } class Menu { controller: ControllerConstructor = Controller createController() { if (this.controller) { return new this.controller('abc'); } return null; } } let t = new Menu(); console.log(t.createController()!.value); ``` ```arkts 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); ``` -------------------------------- ### OHOS Shortcuts Configuration Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md This snippet shows the JSON structure for defining application shortcuts, including ID, label, icon, visibility, and target 'wants' information. It is used in conjunction with metadata in module.json5. ```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" } } ] } ] } ``` -------------------------------- ### Importing and Using HSP Interfaces Source: https://github.com/chenqinggang001/ohos-dev/blob/main/in-app-hsp.md Demonstrates how to import and use interfaces exported from an HSP in an application's entry point. It includes examples of using UI components, utility functions, and accessing resources via the HSP. ```ets // entry/src/main/ets/pages/index.ets import { Log, add, MyTitleBar, ResManager, nativeMulti } from 'library'; import { BusinessError } from "@kit.BasicServicesKit"; import { application} from '@kit.AbilityKit'; const TAG = 'Index'; @Entry @Component struct Index { @State message: string = ''; build() { Column() { List() { ListItem() { MyTitleBar() } .margin({ left: '35px', top: '32px' }) ListItem() { Text(this.message) .fontFamily('HarmonyHeiTi') .fontSize(18) .textAlign(TextAlign.Start) .width('100%') .fontWeight(FontWeight.Bold) } .width('685px') .margin({ top: 30, bottom: 10 }) ListItem() { // ResManager返回的Resource对象,可以传给组件直接使用,也可以从中取出资源来使用 Image(ResManager.getPic()) .id('image') .borderRadius('48px') } .width('685px') .margin({ top: 10, bottom: 10 }) .padding({ left: 12, right: 12, top: 4, bottom: 4 }) ListItem() { Text($r('app.string.add')) .fontSize(18) .textAlign(TextAlign.Start) .width('100%') .fontWeight(500) .height('100%') } .id('add') .borderRadius(24) .width('685px') .height('84px') .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) .margin({ top: 10, bottom: 10 }) .padding({ left: 12, right: 12, top: 4, bottom: 4 }) .onClick(() => { Log.info('add button click!'); this.message = 'result: ' + add(1, 2); }) ListItem() { Text(ResManager.getDesc()) .fontSize(18) .textAlign(TextAlign.Start) .width('100%') .fontWeight(500) .height('100%') } .id('getStringValue') .borderRadius(24) .width('685px') .height('84px') .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) .margin({ top: 10, bottom: 10 }) .padding({ left: 12, right: 12, top: 4, bottom: 4 }) .onClick(() => { // 先通过当前application.createModuleContext获取hsp模块的上下文,再获取hsp模块的resourceManager,然后再调用resourceManager的接口获取资源 application.createModuleContext(this.getUIContext()?.getHostContext(), "library").then((context:Context)=>{ context.resourceManager.getStringValue(ResManager.getDesc().id) .then(value => { console.log('getStringValue is ' + value); this.message = 'getStringValue is ' + value; }) .catch((err: BusinessError) => { console.error('getStringValue promise error is ' + err); }); }).catch((err: BusinessError) => { console.error('createModuleContext promise error is ' + err); }); }) ListItem() { Text($r('app.string.native_multi')) .fontSize(18) .textAlign(TextAlign.Start) .width('100%') .fontWeight(500) .height('100%') } .id('nativeMulti') .borderRadius(24) .width('685px') .height('84px') .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) .margin({ top: 10, bottom: 10 }) .padding({ left: 12, right: 12, top: 4, bottom: 4 }) .onClick(() => { Log.info('nativeMulti button click!'); this.message = 'result: ' + nativeMulti(3, 4); }) } .alignListItem(ListItemAlign.Center) } .width('100%') .backgroundColor($r('app.color.page_background')) .height('100%') } } ``` -------------------------------- ### File Context Menu Profile Structure Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md Example structure of the `menu.json` file used for configuring file context menus. It includes details about ability name, menu item display, handler, and context rules. ```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 } ] } ] } ``` -------------------------------- ### OHOS Wants Tag Configuration Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md This JSON shows the structure for the 'wants' tag, defining the target component for a shortcut, including bundle name, module name, ability name, and optional parameters. ```json { "wants": [ { "bundleName": "com.ohos.hello", "moduleName": "entry", "abilityName": "EntryAbility", "parameters": { "testKey": "testValue" } } ] } ``` -------------------------------- ### ArkTS Namespace Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/getting-started-with-arkts-for-java-programmers.md Demonstrates the use of the `namespace` keyword in ArkTS to organize code, similar to Java's package structure but with explicit namespace declarations. This allows for better code layering and management. ```typescript namespace Models { export class User { // Implementation details. } export interface Repository { // Interface definition. } } ``` -------------------------------- ### OHOS Distribution Filter Configuration Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md This JSON snippet demonstrates the configuration for the 'distributionFilter' tag, used to define HAP distribution strategies based on device specifications like screen shape, window resolution, screen density, and country code. ```json { "module": { "name": "entry1", "type": "entry", "deviceTypes" : [ "tv", "tablet" ] } } ``` -------------------------------- ### App Object Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/app-structure.md A JSON example demonstrating the structure of the app object with sample values. ```JSON { "app": { "bundleName": "com.example.myapplication", "vendor": "example", "version": { "code": 8, "name": "8.0.1" }, "apiVersion": { "compatible": 8, "target": 9, "releaseType": "Beta1" } } } ``` -------------------------------- ### HAR Module Configuration Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/har-package.md An example of the `oh-package.json5` file configuration for a HAR module, specifically showing how to set the entry declaration file for exported interfaces. ```json { "main": "Index.ets" } ``` -------------------------------- ### HAP Debugging with hdc install/uninstall Source: https://github.com/chenqinggang001/ohos-dev/blob/main/hap-package.md Demonstrates how to install, update, and uninstall HAP packages on a device using the hdc install and hdc uninstall commands. Supports installing multiple HAP files simultaneously. ```shell # Install, update, multiple HAPs can specify multiple file paths hdc install entry.hap feature.hap # Execution result install bundle successfully. # Uninstall hdc uninstall com.example.myapplication # Execution result uninstall bundle successfully. ``` -------------------------------- ### ArkTS Class Property Initialization Source: https://github.com/chenqinggang001/ohos-dev/blob/main/getting-started-with-arkts-for-java-programmers.md Illustrates direct property initialization within a class definition in ArkTS. This modern approach simplifies class member setup compared to Java's requirement for explicit constructors or initialization blocks. ```typescript class User { private name: string = 'Default' } ``` -------------------------------- ### OHOS Ability Configuration Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-structure.md Provides a detailed JSON example of an Ability configuration, including properties like name, description, icon, label, launchType, orientation, permissions, visible, skills, configChanges, type, startWindowIcon, startWindowBackground, and removeMissionAfterTerminate. ```json { "abilities": [ { "name": ".EntryAbility", "description": "test main ability", "icon": "$media:ic_launcher", "label": "$string:example", "launchType": "multiton", "orientation": "unspecified", "permissions": [], "visible": true, "skills": [ { "actions": [ "action.system.home" ], "entities": [ "entity.system.home" ] } ], "configChanges": [ "locale", "layout", "fontSize", "orientation" ], "type": "page", "startWindowIcon": "$media:icon", "startWindowBackground": "$color:red", "removeMissionAfterTerminate": true }, { "name": ".PlayService", "description": "example play ability", "icon": "$media:ic_launcher", "label": "$string:example", "launchType": "multiton", "orientation": "unspecified", "visible": false, "skills": [ { "actions": [ "action.play.music", "action.stop.music" ], "entities": [ "entity.audio" ] } ], "type": "service", "backgroundModes": [ "audioPlayback" ] }, { "name": ".UserADataAbility", "type": "data", "uri": "dataability://com.example.world.test.UserADataAbility", "visible": true } ] } ``` -------------------------------- ### ArkTS Module Import Example Source: https://github.com/chenqinggang001/ohos-dev/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 code organization and reusability. ```typescript // Import the ArkTS collections from the ArkTS standard library. import { collections } from '@kit.ArkTS'; ``` -------------------------------- ### Distro JSON Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-structure.md Provides a JSON example of the distro object, showing its configuration for module name, type, installation-free status, and delivery. ```json { "distro": { "moduleName": "ohos_entry", "moduleType": "entry", "installationFree": true, "deliveryWithInstall": true } } ``` -------------------------------- ### OHOS Skills with URIs Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-structure.md An example demonstrating the `skills` object configuration, including `actions`, `entities`, and a `uris` array with detailed URI specifications. ```json { "skills": [ { "actions": [ "action.system.home" ], "entities": [ "entity.system.home" ], "uris": [ { "scheme": "http", "host": "www.example.com", "port": "8080", "path": "query/student/name", "type": "text/*" } ] } ] } ``` -------------------------------- ### Element Resource File Examples Source: https://github.com/chenqinggang001/ohos-dev/blob/main/resource-categories-and-access.md Examples of JSON file structures for different element resource types like color, float, string, and plural. ```json { "color": [ { "name": "color_hello", "value": "#ffff0000" }, { "name": "color_world", "value": "#ff0000ff" } ] } ``` ```json { "float": [ { "name": "font_hello", "value": "28.0fp" }, { "name": "font_world", "value": "20.0fp" } ] } ``` ```json { "string": [ { "name": "string_hello", "value": "Hello" }, { "name": "string_world", "value": "World" }, { "name": "message_arrive", "value": "We will arrive at %1$s." }, { "name": "message_notification", "value": "Hello, %1$s!,You have %2$d new messages." } ] } ``` ```json { "plural": [ { "name": "eat_apple", "value": [ { "quantity": "one", "value": "%d apple" }, { "quantity": "other", "value": "%d apples" } ] } ] } ``` -------------------------------- ### Run OpenHarmony Application Source: https://github.com/chenqinggang001/ohos-dev/blob/main/start-with-ets-stage.md Instructions on how to initiate the application run process on a connected real device. This is typically done via a run button in the IDE's toolbar. ```APIDOC Running the Application: 1. Connect your development board (running OpenHarmony standard system) to your computer. 2. In the IDE's toolbar, locate and click the run button (often depicted as a play icon). - The specific icon may be represented by `zh-cn_image_0000001364054485`. ``` -------------------------------- ### Java 'this' Binding Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/getting-started-with-arkts-for-java-programmers.md Provides an example of how 'this' behaves in Java, always referring to the current instance of the class. Its binding is determined by the code structure at compile time and cannot be changed by how the method is called. ```java class MyClass { void method() { System.out.println(this); // Always refers to the instance of MyClass. } } ``` -------------------------------- ### OpenHarmony工程配置 (build-profile.json5) Source: https://github.com/chenqinggang001/ohos-dev/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" } ] } ``` -------------------------------- ### ArkUI Basic Syntax Overview Reference Source: https://github.com/chenqinggang001/ohos-dev/blob/main/introduction-to-arkts.md Provides a reference link to the ArkUI basic syntax overview for more details on ArkUI features. ```markdown 有关ArkUI功能的更多详细信息,请参见ArkUI[基本语法概述](../ui/state-management/arkts-basic-syntax-overview.md)。 ``` -------------------------------- ### ArkTS 'this' Binding Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/getting-started-with-arkts-for-java-programmers.md Demonstrates the dynamic nature of 'this' binding in ArkTS, where its context depends on how a function is called. The example shows how calling a method without proper binding can lead to errors, and how `.bind()` can be used to explicitly set the 'this' 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); b.callFunction(a.foo); b.callFunction(a.foo.bind(b)) ``` -------------------------------- ### Update Application Configuration Source: https://github.com/chenqinggang001/ohos-dev/blob/main/application-package-install-uninstall.md For developers, updating the application package requires incrementing the 'versionCode' in the app.json5 configuration file before building and releasing. ```APIDOC app.json5: ... "versionCode": , ... Parameters: : An integer representing the new version code. ``` -------------------------------- ### Uninstall Application using bm tool Source: https://github.com/chenqinggang001/ohos-dev/blob/main/application-package-install-uninstall.md Developers can uninstall applications using the 'bm uninstall' command. Refer to the bm tool documentation for detailed usage. ```APIDOC bm uninstall Parameters: : The bundle name of the application to uninstall. ``` -------------------------------- ### Circular Dependency Example in TypeScript Source: https://github.com/chenqinggang001/ohos-dev/blob/main/arkts-migration-background.md Illustrates a circular dependency issue between two TypeScript files ('bar.ets' and 'foo.ets') which can lead to application loading failures. This highlights a limitation in how modules can import each other. ```typescript // bar.ets import {v} from './foo'; // bar.ets依赖foo.ets export let u = 0; // foo.ets import {u} from './bar'; // foo.ets同时又依赖bar.ets export let v = 0; //应用加载失败 ``` -------------------------------- ### Configure Second Page Route Source: https://github.com/chenqinggang001/ohos-dev/blob/main/start-with-ets-stage.md This JSON snippet shows how to add the route for the 'Second' page to the main_pages.json file, enabling navigation to it. ```json { "src": [ "pages/Index", "pages/Second" ] } ``` -------------------------------- ### C++ Native Code Compilation Configuration Source: https://github.com/chenqinggang001/ohos-dev/blob/main/in-app-hsp.md Example of a CMakeLists.txt file used for compiling C++ native code within an HSP module. This file specifies the target library and its source files. ```cpp // library/src/main/cpp/CMakeLists.txt // C++ native code compilation configuration ``` -------------------------------- ### OpenHarmony UI Framework Development Paradigms Source: https://github.com/chenqinggang001/ohos-dev/blob/main/start-overview.md Compares the two development paradigms offered by the ArkUI framework: the declarative development paradigm based on ArkTS and the web-compatible development paradigm based on JS. It highlights differences in language ecosystem, UI update methods, applicable scenarios, and target developers. ```APIDOC UI Framework Development Paradigms: 1. Declarative Development Paradigm (ArkTS): - Language Ecosystem: ArkTS - UI Update Method: Data-driven updates - Applicable Scenarios: Complex applications, high team collaboration - Target Audience: Mobile system application developers, system application developers 2. Web-Compatible Development Paradigm (JS): - Language Ecosystem: JS - UI Update Method: Data-driven updates - Applicable Scenarios: Simple UI applications and cards - Target Audience: Web front-end developers ``` -------------------------------- ### Accessing HSP Resources Source: https://github.com/chenqinggang001/ohos-dev/blob/main/in-app-hsp.md Demonstrates the correct and incorrect ways to access resources within an HSP package. It highlights the use of $r('app.media.example') for correct access and warns against using relative paths which can lead to errors. ```ets // library/src/main/ets/pages/Index.ets // 正确用例 Image($r('app.media.example')) .id('example') .borderRadius('48px') // 错误用例 Image("../../resources/base/media/example.png") .id('example') .borderRadius('48px') ``` -------------------------------- ### ArkTS Optional Type Example Source: https://github.com/chenqinggang001/ohos-dev/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 data structures. ```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-dev/blob/main/getting-started-with-arkts-for-java-programmers.md Shows ArkTS's type inference capability, where the compiler automatically deduces the type of a variable from its assigned value, reducing the need for explicit type declarations. ```typescript let num = 10; // Compiler automatically infers num as type number. ``` -------------------------------- ### ArkTS 对象布局和运算符限制 Source: https://github.com/chenqinggang001/ohos-dev/blob/main/arkts-get-started.md ArkTS禁止在程序执行期间更改对象布局以实现最优性能。此外,它限制了部分运算符的语义,例如一元加法运算符仅能用于数字。 ```ArkTS // 示例:一元加法运算符仅用于数字 let num: number = 5; let result: number = +num; // 有效 // let str: string = "hello"; // let invalidResult: number = +str; // 编译错误 ``` -------------------------------- ### Use Dynamic Imports for Side Effects in ArkTS Source: https://github.com/chenqinggang001/ohos-dev/blob/main/arkts-more-cases.md This example demonstrates the ArkTS rule against importing modules solely for their side effects. It shows how to replace a static import with a dynamic import for such cases. ```arkts import 'module' ``` ```arkts import('module') ``` -------------------------------- ### OHOS Module Configuration Parameters Source: https://github.com/chenqinggang001/ohos-dev/blob/main/module-configuration-file.md Defines key configuration parameters for OHOS modules, including app startup paths, native package information, system theme settings, and UIAbility delegation for redirection. ```APIDOC appStartup: Path to the current Module's startup framework configuration. Supported in entry modules since API version 18, and in HSP/HAR. From API version 20, also supported in feature modules. hnpPackages: Array of Native package information for the current application. Only configurable in entry type modules. systemTheme: Configuration item for the current system theme. Supported from API version 20. Value is a string up to 255 bytes. abilitySrcEntryDelegator: Name of the UIAbility to redirect to. Used in conjunction with abilityStageSrcEntryDelegator. Not effective when UIAbility is started via startAbilityByCall. Not supported in HAR configuration files or redirection to UIAbility in HAR. abilityStageSrcEntryDelegator: Module name corresponding to the UIAbility to redirect to (cannot be the current module name). Used in conjunction with abilitySrcEntryDelegator. Not effective when UIAbility is started via startAbilityByCall. Not supported in HAR configuration files or redirection to UIAbility in HAR. crossAppSharedConfig: Filename for cross-application shared configuration. Effective upon application installation. Supported from API version 20. ``` -------------------------------- ### app.json5 配置文件结构 Source: https://github.com/chenqinggang001/ohos-dev/blob/main/application-configuration-file-overview-stage.md app.json5 文件包含应用的全局配置信息,如Bundle名称、开发厂商、版本号,以及特定设备类型的配置信息。 ```APIDOC app.json5: - 应用的Bundle名称 - 开发厂商 - 版本号 - 特定设备类型的配置信息 ``` -------------------------------- ### module.json5 配置文件结构 Source: https://github.com/chenqinggang001/ohos-dev/blob/main/application-configuration-file-overview-stage.md module.json5 文件包含Module的基本配置信息,如名称、类型、描述、支持的设备类型,以及应用组件(UIAbility, ExtensionAbility)的描述信息和应用运行所需的权限信息。 ```APIDOC module.json5: - Module名称 - Module类型 - Module描述 - 支持的设备类型 - 应用组件信息 (UIAbility, ExtensionAbility) - 应用运行需要的权限信息 ``` -------------------------------- ### Configure Signing for OpenHarmony App Source: https://github.com/chenqinggang001/ohos-dev/blob/main/start-with-ets-stage.md This section details how to configure your OpenHarmony project to automatically generate signatures for your application. This is a crucial step before running the app on a physical device. ```APIDOC Project Structure Configuration: 1. Navigate to **File** > **Project Structure...** 2. Select **Project** > **SigningConfigs**. 3. Check the box for "**Automatically generate signature**". 4. Wait for the automatic signature generation to complete. 5. Click "**OK**" to save the changes. ``` -------------------------------- ### Exporting Classes and Methods in HSP Source: https://github.com/chenqinggang001/ohos-dev/blob/main/in-app-hsp.md Shows how to export custom classes and functions from an HSP module. These exported members can then be imported and used by other HAPs or HSPs. The example exports a `Log` class and `add`, `minus` functions. ```ets // library/src/main/ets/utils/test.ets export class Log { static info(msg: string): void { console.info(msg); } } export function add(a: number, b: number): number { return a + b; } export function minus(a: number, b: number): number { return a - b; } // library/index.ets export { Log, add, minus } from './src/main/ets/utils/test'; ``` -------------------------------- ### ArkTS 强制使用静态类型 Source: https://github.com/chenqinggang001/ohos-dev/blob/main/arkts-get-started.md ArkTS强制使用静态类型,确保变量类型确定,允许编译器在运行前验证代码正确性,减少运行时类型检查,从而提升性能。 ```ArkTS let message: string = "Hello, ArkTS!"; let count: number = 10; function greet(name: string): string { return `Hello, ${name}!`; } ``` -------------------------------- ### app.json5 Configuration Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/app-configuration-file.md This snippet demonstrates the structure and common fields within an app.json5 configuration file for an OHOS application. It includes details like bundle name, version information, resource references, and environment-specific configurations. ```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" } } ``` -------------------------------- ### ArkTS Union Type Example Source: https://github.com/chenqinggang001/ohos-dev/blob/main/getting-started-with-arkts-for-java-programmers.md Demonstrates ArkTS's union types, indicated by the pipe symbol ('|'). Union types allow a variable to hold values of different specified types, enhancing expressiveness for complex scenarios. ```typescript // Union type example. let value: string | number; value = 'hello'; value = 123; ``` -------------------------------- ### Use Specific Types Instead of ESObject in ArkTS Source: https://github.com/chenqinggang001/ohos-dev/blob/main/arkts-more-cases.md This example illustrates the ArkTS rule to avoid using the generic 'ESObject' type. It shows how to replace 'ESObject' with more specific types like 'number', 'string', or custom interfaces for better type safety. ```arkts // lib.d.ts declare function foo(): any; // main.ets let e0: ESObject = foo(); function f() { let e1 = foo(); let e2: ESObject = 1; let e3: ESObject = {}; let e4: ESObject = ''; } ``` ```arkts // lib.d.ts declare function foo(): any; // main.ets interface I {} function f() { let e0: ESObject = foo(); let e1: ESObject = foo(); let e2: number = 1; let e3: I = {}; let e4: string = ''; } ``` -------------------------------- ### Enforce Explicit Type Declarations in ArkTS Source: https://github.com/chenqinggang001/ohos-dev/blob/main/arkts-more-cases.md This example demonstrates how to remove type-checking bypass comments like '// @ts-nocheck' and explicitly declare types for all variables in ArkTS to adhere to strict typing rules. It shows the transformation from using 'any' with bypass comments to specific types. ```arkts // @ts-nocheck var a: any = 123; ``` ```arkts let a: number = 123; ```