DEV Community

Cover image for HarmonyOS Native Development Notes: 01-Meta-Service Development
shaohushuo
shaohushuo

Posted on

HarmonyOS Native Development Notes: 01-Meta-Service Development

Introduction

Meta-service is a lightweight application form in HarmonyOS, which can be run directly without downloading. It is similar to WeChat applet, but different from applet, meta-service is more lightweight.

Meta-service is developed by native and provided at the system level. It is better than applet in terms of ease of use, performance and experience.

Create meta-service

Use DevEco, click Create, select Atomic Service in the template on the left, and select Empty Ability in the template on the right. Click Next according to the prompts.

Icon generation

After the icon is designed, you can use DevEco's built-in generation tool to generate an icon that meets the meta-service specification. In the src/main/resources/media directory, right-click New->Image Asset

A production dialog box will pop up. Select the designed icon and check the main color to generate the meta-service icon.

Write page

Open the src/main/ets/pages/index.ets page. The writing method is consistent with the ArkUI application. Start writing the page code here.

API restrictions

It should be noted that some APIs cannot be used in meta-services. In the HarmonOS document, open the API reference and check Filter meta-service API set on the left to see which APIs may be used in meta-services.

Permission restrictions

There are more permission restrictions in meta-services. In the API documentation, the permissions that support the use of meta-services will be registered at Meta-service API.

Restricted open permissions

Dark mode

In the src/main/resources directory, create a new dark directory, right-click in the resources directory, select Resource Directory, select Color Mode on the left side of the dialog box,
and then click OK

In portable code, referencing color variables through lines such as $r('app.color.primary_button_color') will reference resources/dart/element/color.json in dark mode. In the file, find the corresponding color variable. For other assets, such as images, the same method is used.

Service card

Meta-services can add service cards. For details, see "HarmonyOS Native Development Notes: 02-Service Card Development"

Development and testing

Click Run in DevEco. On the device, you can click the "Search" button above the negative one screen to enter my meta-service list. You can see the newly installed meta-service in the recent.

Listing

For details, see "HarmonyOS Flutter Practice: 13-HarmonyOS Application Packaging and Listing Process". First add the application project, then add the meta-service.

Notes

  1. Click failure problem in the navigation bar. When using RelativeContainer, it is found that if the button is in the same row as the button on the right side of the meta-service at the top, the click event is not triggered. In this case, do not use the RelativeContainer component, and use other components such as Column instead.

References

Top comments (0)