The friends who have been following us must have heard of the "atomic service", and maybe some of the friends have also heard of the "metaservice". Meta services are actually atomic services. So what is the atomic service, the authoritative official analysis is coming~

1. What is the atomization service?

We have become accustomed to the concept of application in our daily lives, and atomized service is a form of user program provided by HarmonyOS for the future. Why do we need a new form of user program?

Traditional applications are device-centric and must be manually installed before use. This causes the application to be firmly fixed on a device as if it is rooted. In the era of the Internet of Everything, the number of devices per capita is constantly increasing. With the diversity of devices and scenarios, each device needs to develop an application independently. The shortcomings of traditional applications such as installation first and incompatibility of different devices are gradually Exposed. In this context, both application providers and users urgently need a new way of providing services to make application development easier and services (such as listening to music, taxis, etc.) more convenient to obtain and use, and atomic services were born.

So what exactly is an atomic service?

Atomic service is a future-oriented service provided by HarmonyOS. It has an independent entrance (the user can directly trigger it by clicking), installation-free (no explicit installation is required, it can be used after installation by the system background), A form of user application that provides users with one or more convenient services.

For example: traditional shopping applications, after adjusting the design according to the atomized service concept, can be realized by multiple service direct, installation-free atomized services, such as "product browsing", "shopping cart", "payment" and so on.

2. Take you to experience the atomization service

Let me take you to experience the atomic service and help you better understand what the atomic service is like.

2.1 Multiple entrances

We can discover atomic services in a variety of ways:

1. One is NFC tag, the other is multi-function code. NFC tags are physically printed tags that support the use of corresponding services with the touch of a mobile phone. The multi-function code can be a physically printed label, which supports the use of corresponding services by touching and scanning the mobile phone, or it can be an electronic label displayed on the screen, which supports scanning. There are two styles of multifunction codes, which are used for cross-device experience and three-party services.

2. Users can also discover and manage atomic services in the service center, desktop and other places of the device.

3. Atomized services can be actively recommended to users based on appropriate scenarios; users can also find services recommended by the system in the service center and Xiaoyi suggestions.

Note: "Xiaoyi" is the name of the voice assistant in Huawei equipment. Xiaoyi can answer user questions, control home equipment, perform user's daily tasks, etc.; moreover, Xiaoyi can perceive users' usage scenarios through different devices and recommend services that users may need.

2.2 Service Card

Unlike traditional applications, atomic services do not have application icons on the device desktop. They display important information on the service center or desktop in the form of service cards. The user clicks on the service card to enter the service interface of the atomic service.

The core concept of the service card is to provide users with easy-to-use and clear information content, integrate intelligent capabilities into the service card experience for users to choose and use, and to meet the display and adaptation on different terminal devices.

It is worth noting that both atomic services and HarmonyOS applications support service cards. For atomized services, service cards are mandatory, and each atomized service has at least one service card. For HarmonyOS applications, the service card is an optional configuration.

Description: HarmonyOS applications are applications that run on the HarmonyOS system and have HarmonyOS features.

2.3 Service Circulation

The atomic service supports running on 1+8+N devices.

●"1" stands for mobile phone

● "8" represents tablets, smart screens, speakers, glasses, watches, car machines, headphones, PCs

● "N" stands for pan-IoT devices with extended scenarios such as sports health, smart home, smart travel, smart office, and audio-visual entertainment.

The transfer capability of atomized services breaks the boundaries of devices, and multi-device linkage enables atomized services to be divided, combined, and transferred, realizing distributed services such as mail cross-device editing, multi-device collaborative fitness, and multi-screen games.

There are two ways to trigger the circulation of atomic services: system recommended circulation and user manual circulation.

①Recommended circulation by the system: When the user uses the atomic service, if there is an optional device with a better user experience in the environment, the system will automatically recommend the device for the user, and the user can confirm whether to initiate the circulation.


②User manual transfer: The user can manually select the appropriate equipment for transfer. After the user clicks on the icon, the transfer panel provided by the system will be called up. The panel will display atomic service information and transferable equipment to guide users to follow-up transfer operations.


2.4 Service sharing

Convenient services provided by atomic services can be quickly shared at short distances by connecting to Huawei Share, so that convenient services can be accurately and quickly pushed to the recipient, reducing the cost of users reaching the service, and improving user experience. Compared with traditional social software sharing, the sharing parties do not need to establish a friend relationship, and the recipient does not need to install the installation package of the bearer service in advance to enjoy the native service experience.

Users can choose to share in the atomization service. After turning on the "Huawei Sharing" switch, the atomization service will be shared with nearby friends who have also turned on the "Huawei Sharing" switch, and the friend will directly start the service after clicking confirm. The picture below is a typical scenario of sharing shopping atomic services through "Huawei Sharing".


3. What are the advantages of atomization services?

3.1 One-time development, multi-terminal deployment

For developers, the atomization service only needs to be developed once and can be deployed on various HarmonyOS terminals, which greatly reduces development costs.

For traditional APP software developers, an inevitable trouble is that the same APP needs to be adapted to different devices. For example, a programmer develops an application on a mobile phone, which needs to be re-adapted to the watch and released to the application market of the watch; after the large screen is adapted, it is released to the application market of the large screen, which seriously affects the efficiency and efficiency of application development. Monetization ability.

At the beginning of the architecture design of HarmonyOS, it proposed the principle of building an architecture that supports multi-terminal deployment at one time. HarmonyOS provides user program framework, Ability framework and UI framework to ensure the consistency of the developed applications when running on multiple terminals. The API of the multi-terminal software platform is consistent to ensure the compatibility of user programs. In this way, developers only need to configure different parameters for different types of devices, and the IDE can automatically generate APP packages that support multi-device distribution. After the APP package is put on the application market, the application market will automatically split, assemble and distribute the HAP package according to the device type, and then realize one-time development end-to-end and support the design of multi-end deployment.


The specific process is as follows:

  1. In the development stage, the IDE compiles and packages application packages that support multiple devices based on the package format.
  2. Shelves to the application market.
  3. The App is unpacked on the cloud side and deployed to a CDN (Content Delivery Network), and the package information is synchronized to the service distribution center.
  4. During the end-side operation, obtain the corresponding HAP and overall summary information according to its own device type.

3.2 Free installation, open in seconds

Consumers do not perceive the installation process and uninstallation process, and experience a new upgrade.

HarmonyOS atomic service is a new species of lightweight service, which provides brand new services and interaction methods. When users use atomic services, if the service is not deployed, the system will automatically deploy the service through the cloud, and the corresponding service can be used after the deployment is successful. For example, by clicking on the service card in the service center, the atomic service completes the deployment and operation through the installation-free capability, realizing a direct service business experience. There is no need for users to jump to the traditional application distribution market, search and download target applications, making the deployment of applications on the device faster.

With the enrichment of the distributed scene ecology, atomic services must always be human-centered and flow between different devices. When the user walks to the big screen device, the video call on the mobile phone can flow to the big screen for communication. When the user walks to the computer, the mobile phone and the computer can work together, and the atomic service can be automatically deployed without disturbing the user. At the same time, the system will intelligently clean up the deployed low-frequency services.

This is the installation-free capability of atomic services. On the one hand, it improves the distribution efficiency and conversion rate of developers' applications on the shelves, on the other hand, it improves the service experience of consumers and reduces the interference of the installation process to users.

3.3 People-centered, distributed circulation

Distributed circulation is the core technology to realize atomized services and take people as the center.

With the development of 5G and IoT devices, individuals owning multiple smart devices have gradually become mainstream scenarios. Smart devices such as mobile phones, notebooks, PADs, TVs, sports watches, earphones, refrigerators, range hoods, smart door locks, etc., are equipped with the HarmonyOS system and connected via a distributed soft bus to form a super terminal. Between different devices, through re-combination of services, a new user experience can be formed.

For example: a user sits at a desk and uses a mobile phone to watch a video, and then wants to move to the living room, sitting on a sofa to continue watching the video on a large screen. Most of the industry uses projection screen solutions, such as DLNA, Cast+, etc. The distributed component circulation technology adopted by the atomic service, in simple terms, is that the HarmonyOS system manages the context of the atomic service process entity (open file handles, hardware, and running status), and cross-device context data Backup, transfer and restore. As shown in the figure below:


For users, the transfer operation should be convenient, efficient, and without side effects. Users can perform repeated circulation, and the application entity can always maintain its state. In order to ensure the consistency of user interaction, the circulation entrance is provided uniformly by the system. The consistency of the application is maintained by the developer. For example: When an application migrates from a mobile phone to a large screen, its controls, styles, layout, etc. should be as consistent as possible. But "consistent" does not mean "the same": the user interface of mobile phones, tablets or large screens should be adapted accordingly to the characteristics of their respective screens.

3.4 What are the advantages of comparing App Clips and Mini Programs?

App Clips and small programs are essentially defining products for the online service and closed-loop transaction scenarios, and naturally pursue the characteristics of being accessible everywhere and direct service. Compared with atomized service, it has the following advantages:

  1. Atomized service is a future-oriented super terminal service form, covering a wider range of IoT devices, with API interfaces compatible with 1+8+N devices. This is also the foundation for atomized services to be more competitive than APP Clips and applets.
  2. Atomic service is designed based on the goal of distributed full-scenario experience, which is also the biggest difference in design concept from App Clips and Mini Programs. HarmonyOS provides super distributed capabilities, allowing developers to quickly implement a distributed business.
  3. Atomized services include service centers, touch, scan, card sharing, and transfer business triggers. Compared with App Clips and Mini Programs, the portals are richer and support quick and direct service.

4. How to develop atomization service?

I believe that many developers are more concerned about how to develop atomic services. Let's introduce it below.

4.1 Overall development requirements

  1. All HAP packages of the atomic service need to meet the installation-free requirements.
  2. The free HAP package cannot exceed 10MB.
  3. When the atomic service is upgraded, the new version must also maintain the installation-free attribute.
  4. Currently, the types of devices that support HAP without installation are: mobile phones, tablets, smart screens, and smart wearables. The versions need to be HarmonyOS 2 and above.
  5. If the atomic service is to be exposed in the service center, it needs to meet:

●The HAP package corresponding to the service needs to include FA, and the only one "MainAbility" is designated as the user operation entry.

●A small size service card (2*2 specification) needs to be configured, as well as basic configuration information: such as icon, name, description, snapshot, etc.

For detailed design instructions of atomic service, please refer to the official website:

4.2 Development Tools

HUAWEI DevEco Studio (hereinafter referred to as DevEco Studio) is based on the open source version of IntelliJ IDEA Community. It is a one-stop integrated development environment (IDE) for all scenarios and devices of Huawei terminals. It provides developers with project template creation, development, compilation, debugging, Released E2E's HarmonyOS application development service.

DevEco Studio download link:

We use DevEco Studio tools to develop atomic services. For detailed instructions on using this tool, please refer to the official website:

4.3 Development process and points of attention

1. Create project

(1) Run the DevEco Studio tool and select File> New> New Project from the menu bar.

(2) According to the project creation wizard, select the required Ability project template, and then click Next.

(3) Configure the basic information of the project.


Project Name : The name of the project, which can be customized.

Project Type : The type of the project, Service represents the atomic service, and Application represents the application that needs to be installed in the traditional way. Because you want to create an atomic service project, select Service here.

Device Type : Select the device type supported by the project as required. Support multiple selection.
Note: If TV is checked, the "Show in Service Center" below will disappear.

Show in Service Center : Whether it is exposed in the service center. When this switch is turned on, a small size (2x2) service card and snapshot will be created by default.

(4) Click Finish, the tool will automatically generate sample code and related resources, and wait for the project to be created.

2. Engineering configuration

(1) config.json configuration file

There is a config.json configuration file in the root directory of each HAP. The content of the file mainly covers the following three aspects:

●The global configuration information of the application includes basic information such as the package name, manufacturer, and version number of the application.

● Application configuration information on specific devices, including application backup and recovery, network security and other capabilities.

●The configuration information of the HAP package includes the basic attributes that each Ability must define (such as package name, class name, type, and capabilities provided by the Ability), as well as the permissions required by the application to access the system or other protected parts of the application.

After the project is created, the config.json file contains the following configuration content by default.

① Free installation configuration information

"distro": { "deliveryWithInstall": true, "moduleName": "entry", "moduleType": "entry", "installationFree": true }

If installationFree is true, it means that the HAP is free of installation.

② Service card configuration information

Since the Show in Service Center switch is turned on when the project is created, this information is configured by default.

"abilities": [


"skills": [



"name": "com.example.atomicservicedemo.MainAbility",

"icon": "$media:icon",

"description": "$string:mainability_description",

"formsEnabled": true,

"label": "$string:app_name",

"type": "page",

"forms": [


"jsComponentName": "widget",

"isDefault": true,

"scheduledUpdateTime": "10:30",

"defaultDimension": "2*2",

"name": "widget",

"description": "$string:widget_description",

"colorMode": "auto",

"type": "JS",

"supportDimensions": [



"updateEnabled": true,

"updateDuration": 1



"launchType": "standard"



For a detailed description of the config.json file, please refer to the official website:

(2) Snapshot

When creating a project, if the Show in Service Center switch is turned on, a snapshot (EntryCard) folder will be automatically generated in the project directory after the project is created. As shown below:


A 2x2 (small size) snapshot (a picture in png format) is generated by default in this folder. Developers can replace it with a pre-designed 2x2 snapshot, and the style should be consistent with the corresponding service card: copy the new snapshot to the above image directory, delete the default image, and the new image name follows the format "service card name-" 2x2.png".

Note: "Service card name" can be viewed in the "name" field in the forms array of the config.json file.

3. Develop atomization service

In the previous tweets, we have already introduced the development of service cards, so I won’t repeat them here, just click the text below.

Understand the operation principle and development method of HarmonyOS service card in one article

We will focus on how to connect atomized services to Huawei to share.

Taking the JAVA project as an example, the development steps are as follows:

① Create two new idl files to share with Huawei for cross-process communication.

IHwShareCallback.idl file:

interface com.huawei.hwshare.third.IHwShareCallback {

[oneway] void notifyState([in] int state);


IHwShareService.idl file:

sequenceable ohos.interwork.utils.PacMapEx;

interface com.huawei.hwshare.third.IHwShareCallback;

interface com.huawei.hwshare.third.IHwShareService {

int startAuth([in] String appId, [in] IHwShareCallback callback);

int shareFaInfo([in] PacMapEx pacMapEx);


Developers only need to save the .idl file to the src/ directory of the DevEco Studio project, and the tool will generate the IRemoteObject interface file, Stub file, and Proxy file in the generated/ directory of the project when building the application. IHwShareCallback.idl file and IHwShareService.idl file will generate corresponding IHwShareCallback.java and IHwShareService.java.

② Create a new management class "
ShareAtomicServiceManager.java", used to manage the cross-process communication shared with Huawei.

An interface is exposed here:

public void shareFaInfo(String appId, PacMapEx pacMap) {

if (mContext == null) {



mAppId = appId;

mSharePacMap = pacMap;





●appId is the unique identifier of the application in the application market, which is generated when the project is created.

●pacMap is the information that needs to be passed to Huawei to share.

●shareFaInfo() is used to share FA information to Huawei share application, the code is as follows:

private void shareFaInfo() {

if (mShareService == null) {



if (mHasPermission) {

HiLog.info(LABEL_LOG, LOG_FORMAT, TAG, "start shareFaInfo.");

try {


mSharePacMap = null;

} catch (RemoteException e) {

HiLog.error(LABEL_LOG, LOG_FORMAT, TAG, "shareFaInfo error.");



// Disconnect when not in use

mHandler.postTask(mTask, UNBIND_TIME);


Among them, mTask is used to perform disconnection operations:

private final Runnable mTask = () -> {

if (mContext != null && mShareService != null) {


mHasPermission = false;

mShareService = null;



In addition, the code to bind the Huawei sharing service is as follows:

private void bindShareService() {

if (mShareService != null) {

// It is guaranteed to connect only once.



HiLog.info(LABEL_LOG, LOG_FORMAT, TAG, "start bindShareService.");

Operation operation = new Intent.OperationBuilder().withBundleName(SHARE_PKG_NAME)


Intent intent = new Intent();


mContext.connectAbility(intent, mConnection);

Among them, the definition of mConnection is as follows:

// Manage the connection shared with Huawei private final IAbilityConnection mConnection = new IAbilityConnection() {@Override public void onAbilityConnectDone(ElementName elementName,
IRemoteObjectiRemoteObject,int i) {HiLog.error(LABEL_LOG, LOG_FORMAT,TAG,"onAbilityConnectDonesuccess."); mHandler.postTask(()->{mShareService = new HwShareServiceProxy(iRemoteObject); try {mShareService.startAuth(mAppId, mFaCallback); } catch (RemoteException e) {HiLog.error(LABEL_LOG,LOG_FORMAT,TAG,"startAuth error."); }});} @Override public void on AbilityDisconnectDone(ElementName elementName, int i) {HiLog.info(LABEL_LOG,LOG_FORMAT,TAG,"onAbilityDisconnectDone."); mHandler.postTask(()->{mShareService=null;mHasPermission=false;});}};

mShareService.startAuth(mAppId, mFaCallback) is to verify the appId. After the verification is successful, it will be called back through mFaCallback.

The code of mFaCallback is as follows:

private final HwShareCallbackStub mFaCallback = new HwShareCallbackStub("HwShareCallbackStub") {


public void notifyState(int state) throws RemoteException {


HiLog.info(LABEL_LOG, LOG_FORMAT, TAG, "notifyState: " + state);

if (state == 0) {

mHasPermission = true;

if (mSharePacMap != null) {







When state is 0, it means that the authentication is passed and sharing is possible.

③ In MainAbilitySlice.java, call the interface to connect to Huawei Share:

ShareAtomicServiceManager.getInstance(this).shareFaInfo("629005930163350400", getPacMap());

"629005930163350400" is the appId, which is different for each application and needs to be replaced with the application's own appId. getPacMap is an encapsulation method for obtaining the content that needs to be shared.

private PacMapEx getPacMap() {

PacMapEx pacMap = new PacMapEx();

pacMap.putObjectValue(ShareAtomicServiceManager.SHARING_FA_TYPE, 0);

pacMap.putObjectValue(ShareAtomicServiceManager.HM_BUNDLE_NAME, getBundleName());

ShareAtomicServiceManager.SHARING_EXTRA_INFO, "Atomic Service Sharing Extra Content");

pacMap.putObjectValue(ShareAtomicServiceManager.HM_ABILITY_NAME, MainAbility.class.getName());

ShareAtomicServiceManager.SHARING_CONTENT_INFO, "The content shared by the Atomic Service through Huawei");

byte[] sharedContentImg = getResourceBytes(ResourceTable.Media_share_conteng_img);

pacMap.putObjectValue(ShareAtomicServiceManager.SHARING_THUMB_DATA, sharedContentImg);

byte[] iconImg = getResourceBytes(ResourceTable.Media_icon);

pacMap.putObjectValue(ShareAtomicServiceManager.HM_FA_ICON, iconImg);

pacMap.putObjectValue(ShareAtomicServiceManager.HM_FA_NAME, getString(ResourceTable.String_app_name));

return pacMap;


Among them, the definition of constants is as follows:

public static final String HM_FA_ICON = "ohos_fa_icon";

public static final String HM_FA_NAME = "ohos_fa_name";

public static final String HM_ABILITY_NAME = "ohos_ability_name";

public static final String HM_BUNDLE_NAME = "ohos_bundle_name";

public static final String SHARING_FA_TYPE = "sharing_fa_type";

public static final String SHARING_THUMB_DATA = "sharing_fa_thumb_data";

public static final String SHARING_CONTENT_INFO = "sharing_fa_content_info";

public static final String SHARING_EXTRA_INFO = "sharing_fa_extra_info";

The meanings of the constants are explained as follows:


For the analysis of image resources, please refer to the following:

private byte[] getResourceBytes(int resId) {

InputStream resource = null;

ByteArrayOutputStream outStream = null;

try {

resource = getResourceManager().getResource(resId);

outStream = new ByteArrayOutputStream();

byte[] buffer = new byte[1024];

int len;

while ((len = resource.read(buffer)) != -1) {

outStream.write(buffer, 0, len);




return outStream.toByteArray();

} catch (IOException e) {

HiLog.error(TAG, "get resource occurs io exception!");

} catch (NotExistException e) {

HiLog.error(TAG, "it dose not exist!");

} finally {

if (resource != null) {

try {


} catch (IOException e) {

HiLog.error(TAG, "close input stream occurs io exception!");



if (outStream != null) {

try {


} catch (IOException e) {

HiLog.error(TAG, "close output stream occurs io exception!");




return null;


You can also refer to the development guidance shared by Huawei on the official website:


4. Run the project

After the virtual machine or real machine runs the created project, the main interface of the atomization service (that is, the service interface) will be displayed. But the atomized service icon cannot be found on the desktop, because the atomized service does not have an icon on the desktop. You can find the atomized service by searching the name of the atomized service in the service center, and add its service card to the desktop.

To access the operating results shared by Huawei, the atomic service requires two HarmonyOS mobile phones, and the system software version is not lower than HarmonyOS 2.


The above is the introduction of the atomic service in this issue. Have you got it? We look forward to more developers joining us and starting your journey of atomic service development~

19 声望4 粉丝