harmony 鸿蒙Setting the Icon and Name of a Mission Snapshot

  • 2023-06-24
  • 浏览 (550)

Setting the Icon and Name of a Mission Snapshot

Setting a unique icon and name for each mission snapshot of an application helps you better manage the missions and functions of the application.

By default, the icon and label fields in the abilities tag of the module.json5 file are used to set the icon and label.

Figure 1 Mission snapshot of a UIAbility

You can also use UIAbilityContext.setMissionIcon() and UIAbilityContext.setMissionLabel() to customize the icon and name for a mission snapshot. For example, for a UIAbility instance in multiton mode, you can configure the icon and name for each mission snapshot based on different functions.

This document describes the following operations:

Setting a Mission Snapshot Icon (for System Applications Only)

Call UIAbilityContext.setMissionIcon() to set the icon of a mission snapshot. For details about how to obtain the context, see Obtaining the Context of UIAbility. For details about how to obtain the PixelMap information in the example, see Image Decoding.

import common from '@ohos.app.ability.common';

let context: common.UIAbilityContext = ...; // UIAbilityContext
let pixelMap: PixelMap =...; // PixelMap information of the image.

context.setMissionIcon(pixelMap, (err) => {
  if (err.code) {
    console.error(`Failed to set mission icon. Code is ${err.code}, message is ${err.message}`);
  }
})

The display effect is shown below.

Figure 2 Mission snapshot icon

Setting a Mission Snapshot Name

Call UIAbilityContext.setMissionLabel() to set the name of a mission snapshot.

import common from '@ohos.app.ability.common';
import { BusinessError } from '@ohos.base';

let context: common.UIAbilityContext = this.context; // UIAbilityContext

context.setMissionLabel('test').then(() => {
  console.info('Succeeded in seting mission label.');
}).catch((err: BusinessError) => {
  console.error(`Failed to set mission label. Code is ${err.code}, message is ${err.message}`);
});

The display effect is shown below.

Figure 3 Mission snapshot name

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Application Models

harmony 鸿蒙Using Explicit Want to Start an Application Component

harmony 鸿蒙Using Implicit Want to Open a Website

harmony 鸿蒙AbilityStage Component Container

harmony 鸿蒙Accessing a DataAbility

harmony 鸿蒙Accessing a DataShareExtensionAbility from the FA Model

harmony 鸿蒙AccessibilityExtensionAbility

harmony 鸿蒙Common action and entities Values

harmony 鸿蒙API Switching Overview

harmony 鸿蒙Switching of app and deviceConfig

0  赞