HarmonyOS practice - development overview

catalogue

What is the HarmonyOS operating system:

HarmonyOS has three characteristics:

Technical architecture:

Distributed soft bus:

Distributed device virtualization:

Distributed data management:

Distributed task scheduling

One time development, multi terminal deployment

Unified OS, flexible deployment

Equipment certificate certification process:

HarmonyOS development history:

Introduction case - jump to the page:

Implementation steps:

1. Write the first page (text + button):

2. Write the second page (text):

3. Add a jump to the button:

What is the HarmonyOS operating system:

HarmonyOS is a new distributed operating system for the era of Internet of all things.

Based on the traditional single device system capability, HarmonyOS puts forward a distributed concept based on the same set of system capability and adapting to multiple terminal forms, which can support a variety of terminal devices such as mobile phone, tablet, smart wear, smart screen and car machine, and provide the business capability of the whole scene (mobile office, sports health, social communication, media entertainment, etc.).

HarmonyOS has three characteristics:

  • The devices equipped with the operating system are integrated at the system level to form a super terminal, so that the hardware capacity of the devices can be expanded flexibly, so as to realize hardware mutual assistance and resource sharing between devices.

    For consumers, HarmonyOS can integrate the capabilities of various terminals in the life scene, realize rapid connection, capability mutual assistance and resource sharing between different terminal devices, match appropriate devices and provide a smooth whole scene experience.

  • For developers, realize one-time development and multi terminal deployment.

    For application developers, HarmonyOS adopts a variety of distributed technologies to make application development independent of the morphological differences of different terminal devices, so that developers can focus on the upper business logic and develop applications more conveniently and efficiently.

  • A set of operating system can meet the equipment requirements of different capabilities, realize unified OS and flexible deployment.

    For device developers, HarmonyOS adopts a component-based design scheme, which can be flexibly tailored according to the resource capacity and business characteristics of the device, so as to meet the requirements of different forms of terminal devices for the operating system.

HarmonyOS provides API s that support multiple development languages for developers to develop applications. Supported development languages include Java, XML (Extensible Markup Language), C/C + +, JS (JavaScript), CSS (Cascading Style Sheets) and HML (harmony OS markup language).

Technical architecture:

HarmonyOS follows the layered design as a whole, from bottom to top: kernel layer, system service layer, framework layer and application layer. The system functions are expanded level by level according to "system > subsystem > function / module". In the scenario of multi device deployment, some unnecessary subsystems or functions / modules can be tailored according to the actual needs. The technical architecture of HarmonyOS is as follows:

Distributed soft bus:

Distributed soft bus is the communication base of distributed devices such as mobile phone, tablet, smart wearable, smart screen and car machine. It provides a unified distributed communication capability for the interconnection between devices and creates conditions for senseless discovery and zero waiting transmission between devices. Developers only need to focus on the implementation of business logic without paying attention to networking mode and underlying protocol.

Distributed device virtualization:

The distributed device virtualization platform can realize the resource integration, device management and data processing of different devices, and a variety of devices together form a super virtual terminal. For different types of tasks, match and select appropriate execution hardware for users, so that business can flow continuously between different devices, and give full play to the capability advantages of different devices, such as display capability, camera capability, audio capability, interaction capability and sensor capability.

Distributed data management:

Distributed data management is based on the ability of distributed soft bus to realize the distributed management of application data and user data. User data is no longer bound to a single physical device, and business logic is separated from data storage. Cross device data processing is as convenient and fast as local data processing, so that developers can easily realize data storage, sharing and access under the whole scene and multiple devices, creating the basic conditions for creating a consistent and smooth user experience.

Distributed task scheduling

Distributed task scheduling is based on distributed soft bus, distributed data management, distributed Profile and other technical features, Build a unified distributed service management (discovery, synchronization, registration and invocation) mechanism to support remote startup, remote invocation, remote connection and migration of cross device applications. It can select appropriate devices to run distributed tasks according to the capabilities, locations, business operation status, resource usage of different devices, as well as users' habits and intentions.

One time development, multi terminal deployment

HarmonyOS provides user program framework, Ability framework and UI framework, supports the reuse of multi terminal business logic and interface logic in the process of application development, realizes one-time development and multi terminal deployment of applications, and improves the development efficiency of cross device applications.

Among them, the UI framework supports Java and JS development languages, and provides rich polymorphic controls, which can display different UI effects on mobile phones, tablets, smart wear, smart screens and car machines. Adopt the mainstream design method in the industry, provide a variety of responsive layout schemes, support grid layout, and meet the interface adaptability of different screens.

Unified OS, flexible deployment

Through component-based and miniaturization design methods, HarmonyOS supports flexible deployment of a variety of terminal devices on demand, and can adapt to different types of hardware resources and functional requirements. Support the automatic generation of component-based dependencies through the compilation chain relationship to form a component tree dependency diagram, support the convenient development of product system and reduce the development threshold of hardware equipment.

  • Support the selection of components (components are optional): the required components can be selected according to the form and requirements of hardware.
  • Support the configuration of function sets in components (components can be large or small): you can choose to configure the function sets in components according to hardware resources and functional requirements. For example, you can choose to configure some controls in graphics framework components.
  • Support dependency association between components (the platform can be large or small): component dependency can be automatically generated according to the compilation chain relationship. For example, if you select a graphics framework component, you will automatically select the dependent graphics engine component, etc.

Equipment certificate certification process:

HarmonyOS development history:

task

brief introduction

Meet HarmonyOS

  • Understand the system positioning, architecture and technical characteristics of HarmonyOS.
  • Understand the basic concepts and knowledge of HarmonyOS application development.

Prepare development environment

  • Install development tools and configure relevant development environment.
  • Quickly build the first application and be familiar with the HarmonyOS application development process.

Develop Ability

Capability is an important part of HarmonyOS application, which is divided into FA (feature capability) and PA (particle capability):

  • FA supports Page Ability: Page template is the only template supported by FA, which is used to provide the ability to interact with users.

  • PA supports Service capability and Data capability: the Service template is used to provide the ability to run tasks in the background; The Data template is used to provide a unified Data access abstraction for external users.

To develop HarmonyOS applications, you must first understand how Ability is used.

Develop UI

FA needs to provide UI to interact with users. HarmonyOS provides two UI frameworks: Java UI and JS UI: Java UI provides fine-grained UI programming interface to make application development more flexible; JS UI provides relatively high-level UI description, which makes application development easier.

Develop business functions

  • Media: development of video, audio, image, camera and other functions.
  • Security: development of permissions, biometrics and other functions.
  • AI: development of image super division, speech recognition, code generation and other functions.
  • Network connection: development of NFC, Bluetooth, WLAN and other functions.
  • Equipment management: development of sensor, control small devices, location and other functions.
  • Data management: development of database, distributed data / file service, data search and other functions.
  • Thread: development of thread management, inter thread communication and other functions.
  • IDL: declare system services and service interfaces provided by Ability, and generate relevant codes.

Debug application

If you need to debug applications on real devices, you need to apply for debugging certificates and configure signature information before compiling. In order to generate HAP with signature information when compiling and building.

If you debug the application on the simulator, you don't need to sign, just compile and build HAP directly.

Publish application

If you need to publish to the application market, you need to apply for a release certificate, sign the APP, and then apply for listing.

Introduction case - jump to the page:

Implementation steps:

1. Write the first page (text + button):

Using XML file method!!!

In ability_ main. Write a presentation page in XML:

<?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">
 
    <!--Page display content-->
    <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="First page"
        ohos:text_size="40vp"
        />
 
    <!--Write a button-->
    <Button
        ohos:id="$+id:but1"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:background_element="red"
        ohos:text="Point me"
        ohos:text_size="40fp"/>
 
</DirectionalLayout>

2. Write the second page (text):

Using Java code!!!

Create a new Ability:

Write the page layout in the SecondAbilitySlice file:

package com.example.myapplication.slice;
 
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
 
public class SecondAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        //super.setUIContent(ResourceTable.Layout_ability_second);
 
        //1. Create layout object:
        DirectionalLayout directionalLayout = new DirectionalLayout(this);
 
        //2. Create text object:
        Text text = new Text(this);
        //Setting content:
        text.setText("Second page");
        //Set text size:
        text.setTextSize(55);
        //Set text color
        text.setTextColor(Color.BLUE);
 
        //3. Add a text object to the layout:
        directionalLayout.addComponent(text);
 
        //4. Add the layout to the sub interface:
        super.setUIContent(directionalLayout);
    }
 
    @Override
    public void onActive() {
        super.onActive();
    }
 
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}

3. Add a jump to the button:

Add functions in MainAbilitySlice:

package com.example.myapplication.slice;
 
import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
 
//Sub page:
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener{ //Implement the click event interface component ClickedListener
 
    Button button = null;
 
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
 
        //1. Find the button and click the id attribute of the button:
        button = (Button) findComponentById(ResourceTable.Id_but1); //Cast type to Button
 
        //2. Add a click event to the button:
        //After clicking the button with the mouse, you can execute the onClick method in this class
        button.setClickedListener(this); //This represents the object of this class
    }
 
    @Override
    public void onActive() {
        super.onActive();
    }
 
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
 
    @Override
    public void onClick(Component component) {
        //After clicking the button, execute the function: (jump to the page)
        if(component == button){
            //1. Only after clicking this button can the jump be executed:
 
            //2. Specify which page to jump to: (intention)
            Intent intent = new Intent();
 
            //3. Include the page information to jump to:
            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")//The device to jump to. If you pass a string without content, it means to jump to the local machine
                    .withBundleName("com.example.myapplication")//Specify the jump application, and fill in the package name of the specified application with the parameters in parentheses
                    .withAbilityName("com.example.myapplication.SecondAbility")//Specify the page to jump to
                    .build();//Package the above three information
 
            //4. Set the packaged operation to the intended value
            intent.setOperation(operation);
 
            //5. Jump to page:
            startAbility(intent);
 
        }
    }
}

[this article is participating in the "prize essay | harmony OS essay contest"]

Transfer port: https://marketing.csdn.net/p/ad3879b53f4b8b31db27382b5fc65bbc

Keywords: harmonyos

Added by roy on Tue, 04 Jan 2022 00:13:59 +0200