harmony 鸿蒙@ohos.application.missionManager (missionManager)

  • 2022-12-22
  • 浏览 (550)

@ohos.application.missionManager (missionManager)

The missionManager module provides APIs to lock, unlock, and clear missions, and switch a mission to the foreground.

NOTE

The APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use @ohos.app.ability.missionManager instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import missionManager from '@ohos.application.missionManager';

Required Permissions

ohos.permission.MANAGE_MISSIONS

missionManager.registerMissionListener

registerMissionListener(listener: MissionListener): number;

Registers a listener to observe the mission status.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
listener MissionListener Yes Mission status listener to register.

Return value

Type Description
number Index of the mission status listener, which is created by the system and allocated when the listener is registered.

Example

import missionManager from '@ohos.application.missionManager';

console.log('registerMissionListener');
let listenerid = missionManager.registerMissionListener({
  onMissionCreated: (mission) => {console.log('--------onMissionCreated-------');},
  onMissionDestroyed: (mission) => {console.log('--------onMissionDestroyed-------');},
  onMissionSnapshotChanged: (mission) => {console.log('--------onMissionSnapshotChanged-------');},
  onMissionMovedToFront: (mission) => {console.log('--------onMissionMovedToFront-------');},
  onMissionIconUpdated: (mission, icon) => {console.log('--------onMissionIconUpdated-------');},
  onMissionClosed: (mission) => {console.log('--------onMissionClosed-------');},
  onMissionLabelUpdated: (mission) => {console.log('--------onMissionLabelUpdated-------');}
});

missionManager.unregisterMissionListener

unregisterMissionListener(listenerId: number, callback: AsyncCallback<void>): void;

Deregisters a mission status listener. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
listenerId number Yes Index of the mission status listener to deregister. It is returned by registerMissionListener().
callback AsyncCallback<void> Yes Callback used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';

  console.log('registerMissionListener');
  let listenerid = missionManager.registerMissionListener({
    onMissionCreated: (mission) => {console.log('--------onMissionCreated-------');},
    onMissionDestroyed: (mission) => {console.log('--------onMissionDestroyed-------');},
    onMissionSnapshotChanged: (mission) => {console.log('--------onMissionSnapshotChanged-------');},
    onMissionMovedToFront: (mission) => {console.log('--------onMissionMovedToFront-------');},
    onMissionIconUpdated: (mission, icon) => {console.log('--------onMissionIconUpdated-------');},
    onMissionClosed: (mission) => {console.log('--------onMissionClosed-------');},
    onMissionLabelUpdated: (mission) => {console.log('--------onMissionLabelUpdated-------');}
  });

  missionManager.unregisterMissionListener(listenerid, (error) => {
      console.error('unregisterMissionListener fail, error: ${error}');
  });

missionManager.unregisterMissionListener

unregisterMissionListener(listenerId: number): Promise<void>;

Deregisters a mission status listener. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
listenerId number Yes Index of the mission status listener to deregister. It is returned by registerMissionListener().

Return value

Type Description
Promise<void> Promise used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';
  import { BusinessError } from '@ohos.base';

  console.log('registerMissionListener');
  let listenerid = missionManager.registerMissionListener({
    onMissionCreated: (mission) => {console.log('--------onMissionCreated-------');},
    onMissionDestroyed: (mission) => {console.log('--------onMissionDestroyed-------');},
    onMissionSnapshotChanged: (mission) => {console.log('--------onMissionSnapshotChanged-------');},
    onMissionMovedToFront: (mission) => {console.log('--------onMissionMovedToFront-------');},
    onMissionIconUpdated: (mission, icon) => {console.log('--------onMissionIconUpdated-------');},
    onMissionClosed: (mission) => {console.log('--------onMissionClosed-------');},
    onMissionLabelUpdated: (mission) => {console.log('--------onMissionLabelUpdated-------');}
  });

  missionManager.unregisterMissionListener(listenerid).catch((error: BusinessError) => {
      console.error('unregisterMissionListener fail, error: ${error}');
  });

missionManager.getMissionInfo

getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<MissionInfo>): void;

Obtains the information about a given mission. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
deviceId string Yes Device ID. It is a null string by default for the local device.
missionId number Yes Mission ID.
callback AsyncCallback<MissionInfo> Yes Callback used to return the mission information obtained.

Example

  import missionManager from '@ohos.application.missionManager';
  import { BusinessError } from '@ohos.base';

  let allMissions=missionManager.getMissionInfos('',10).catch((err: BusinessError) => {
    console.log('${err}');});
  missionManager.getMissionInfo('', allMissions[0].missionId, (error, mission) => {
    if (error.code) {
      console.error('getMissionInfo failed, error.code: ${error.code}, error.message: ${error.message}');
      return;
    }

    console.log('mission.missionId = ${mission.missionId}');
    console.log('mission.runningState = ${mission.runningState}');
    console.log('mission.lockedState = ${mission.lockedState}');
    console.log('mission.timestamp = ${mission.timestamp}');
    console.log('mission.label = ${mission.label}');
    console.log('mission.iconPath = ${mission.iconPath}');
  });

missionManager.getMissionInfo

getMissionInfo(deviceId: string, missionId: number): Promise<MissionInfo>;

Obtains the information about a given mission. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
deviceId string Yes Device ID. It is a null string by default for the local device.
missionId number Yes Mission ID.

Return value

Type Description
Promise<MissionInfo> Promise used to return the mission information obtained.

Example

  import missionManager from '@ohos.application.missionManager';
  import { BusinessError } from '@ohos.base';

  let mission = missionManager.getMissionInfo('', 10).catch((error: BusinessError) => {
      console.error('getMissionInfo fail, error: ${error}');
  });

missionManager.getMissionInfos

getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback<Array<MissionInfo>>): void;

Obtains information about all missions. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
deviceId string Yes Device ID. It is a null string by default for the local device.
numMax number Yes Maximum number of missions whose information can be obtained.
callback AsyncCallback<Array<MissionInfo>> Yes Callback used to return the array of mission information obtained.

Example

  import missionManager from '@ohos.application.missionManager';

  missionManager.getMissionInfos('', 10, (error, missions) => {
      if (error.code) {
          console.error(`getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}`);
          return;
      }
      console.log(`size = ${missions.length}`);
      console.log(`missions = ${JSON.stringify(missions)}`);
  });

missionManager.getMissionInfos

getMissionInfos(deviceId: string, numMax: number): Promise<Array<MissionInfo>>;

Obtains information about all missions. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
deviceId string Yes Device ID. It is a null string by default for the local device.
numMax number Yes Maximum number of missions whose information can be obtained.

Return value

Type Description
Promise<Array<MissionInfo>> Promise used to return the array of mission information obtained.

Example

  import missionManager from '@ohos.application.missionManager';
  import { BusinessError } from '@ohos.base';

  let allMissions = missionManager.getMissionInfos('', 10).catch((error: BusinessError) => {
      console.error('getMissionInfos fail, error: ${error}');
  });

missionManager.getMissionSnapShot

getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback<MissionSnapshot>): void;

Obtains the snapshot of a given mission. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
deviceId string Yes Device ID. It is a null string by default for the local device.
missionId number Yes Mission ID.
callback AsyncCallback<MissionSnapshot> Yes Callback used to return the snapshot information obtained.

Example

  import missionManager from '@ohos.application.missionManager';

  missionManager.getMissionInfos('', 10, (error, missions) => {
    if (error.code) {
        console.error(`getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}`);
        return;
    }
    console.log(`size = ${missions.length}`);
    console.log(`missions = ${JSON.stringify(missions)}`);
    let id = missions[0].missionId;

    missionManager.getMissionSnapShot('', id, (error, snapshot) => {
      if (error.code) {
          console.error(`getMissionSnapShot failed, error.code: ${error.code}, error.message: ${error.message}`);
          return;
      }
      console.log(`bundleName = ${snapshot.ability.bundleName}`);
    });
  });

missionManager.getMissionSnapShot

getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnapshot>;

Obtains the snapshot of a given mission. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
deviceId string Yes Device ID. It is a null string by default for the local device.
missionId number Yes Mission ID.

Return value

Type Description
Promise<MissionSnapshot> Promise used to return the snapshot information obtained.

Example

  import missionManager from '@ohos.application.missionManager';
  import { BusinessError } from '@ohos.base';

  let id: number = -1;
  missionManager.getMissionInfos('',10).then((res) => {
    let allMissions = res;
    console.log(`size = ${allMissions.length}`);
    console.log(`missions = ${JSON.stringify(allMissions)}`);
    id = allMissions[0].missionId;
  }).catch((error: BusinessError) => {
    console.error(`getMissionInfos fail, error: ${error}`);
  });

  let snapshot = missionManager.getMissionSnapShot('', id).catch((error: BusinessError) => {
    console.error(`getMissionSnapShot fail, error: ${error}`);
  });

missionManager.lockMission

lockMission(missionId: number, callback: AsyncCallback<void>): void;

Locks a given mission. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
missionId number Yes Mission ID.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';

  missionManager.getMissionInfos('', 10, (error, missions) => {
    if (error.code) {
        console.error(`getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}`);
        return;
    }
    console.log(`size = ${missions.length}`);
    console.log(`missions = ${JSON.stringify(missions)}`);
    let id = missions[0].missionId;

    missionManager.lockMission(id).then(() => {
  	  console.log('lockMission is called ');
    });
  });

missionManager.lockMission

lockMission(missionId: number): Promise<void>;

Locks a given mission. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
missionId number Yes Mission ID.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';
  import { BusinessError } from '@ohos.base';

  let id: number = -1;
  missionManager.getMissionInfos('',10).then((res) => {
    let allMissions = res;
    console.log(`size = ${allMissions.length}`);
    console.log(`missions = ${JSON.stringify(allMissions)}`);
    id = allMissions[0].missionId;
  }).catch((error: BusinessError) => {
      console.error(`getMissionInfos fail, error: ${error}`);
  });

  missionManager.lockMission(id).catch((error: BusinessError) => {
      console.error(`lockMission fail, error: ${error}`);
  });

missionManager.unlockMission

unlockMission(missionId: number, callback: AsyncCallback<void>): void;

Unlocks a given mission. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
missionId number Yes Mission ID.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';

  missionManager.getMissionInfos('', 10, (error, missions) => {
    if (error.code) {
        console.error(`getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}`);
        return;
    }
    console.log(`size = ${missions.length}`);
    console.log(`missions = ${JSON.stringify(missions)}`);
    let id = missions[0].missionId;

    missionManager.unlockMission(id).then(() => {
  	  console.log('unlockMission is called ');
    });
  });

missionManager.unlockMission

unlockMission(missionId: number): Promise<void>;

Unlocks a given mission. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
missionId number Yes Mission ID.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';
  import { BusinessError } from '@ohos.base';

  let id: number = -1;
  missionManager.getMissionInfos('',10).then((res) => {
    let allMissions = res;
    console.log(`size = ${allMissions.length}`);
    console.log(`missions = ${JSON.stringify(allMissions)}`);
    id = allMissions[0].missionId;
  }).catch((error: BusinessError) => {
      console.error(`getMissionInfos fail, error: ${error}`);
  });

  missionManager.lockMission(id).catch((error: BusinessError) => {
      console.error(`lockMission fail, error: ${error}`);
  });
  missionManager.unlockMission(id).catch((error: BusinessError) => {
      console.error(`unlockMission fail, error: ${error}`);
  });

missionManager.clearMission

clearMission(missionId: number, callback: AsyncCallback<void>): void;

Clears a given mission, regardless of whether it is locked. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
missionId number Yes Mission ID.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';

  missionManager.getMissionInfos('', 10, (error, missions) => {
    if (error.code) {
        console.error(`getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}`);
        return;
    }
    console.log(`size = ${missions.length}`);
    console.log(`missions = ${JSON.stringify(missions)}`);
    let id = missions[0].missionId;

    missionManager.clearMission(id).then(() => {
  	  console.log('clearMission is called ');
    });
  });

missionManager.clearMission

clearMission(missionId: number): Promise<void>;

Clears a given mission, regardless of whether it is locked. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
missionId number Yes Mission ID.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';
  import { BusinessError } from '@ohos.base';

  let id: number = -1;
  missionManager.getMissionInfos('',10).then((res) => {
    let allMissions = res;
    console.log(`size = ${allMissions.length}`);
    console.log(`missions = ${JSON.stringify(allMissions)}`);
    id = allMissions[0].missionId;
  }).catch((error: BusinessError) => {
      console.error(`getMissionInfos fail, error: ${error}`);
  });

  missionManager.clearMission(id).catch((error: BusinessError) => {
    console.error(`clearMission fail, error: ${error}`);
  });

missionManager.clearAllMissions

clearAllMissions(callback: AsyncCallback<void>): void;

Clears all unlocked missions. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Example

  import missionManager from '@ohos.application.missionManager'

  missionManager.clearAllMissions().then(() => {
    console.log('clearAllMissions is called ');
  });

missionManager.clearAllMissions

clearAllMissions(): Promise<void>;

Clears all unlocked missions. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';
  import { BusinessError } from '@ohos.base';

  missionManager.clearAllMissions().catch((error: BusinessError) => {
      console.error('clearAllMissions fail, error: ${error}');
  });

missionManager.moveMissionToFront

moveMissionToFront(missionId: number, callback: AsyncCallback<void>): void;

Switches a given mission to the foreground. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
missionId number Yes Mission ID.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';

  missionManager.getMissionInfos('', 10, (error, missions) => {
    if (error.code) {
        console.error(`getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}`);
        return;
    }
    console.log(`size = ${missions.length}`);
    console.log(`missions = ${JSON.stringify(missions)}`);
    let id = missions[0].missionId;

    missionManager.moveMissionToFront(id).then(() => {
  	  console.log('moveMissionToFront is called ');
    });
  });

missionManager.moveMissionToFront

moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCallback<void>): void;

Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
missionId number Yes Mission ID.
options StartOptions Yes Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';

  missionManager.getMissionInfos('', 10, (error, missions) => {
    if (error.code) {
        console.error(`getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}`);
        return;
    }
    console.log(`size = ${missions.length}`);
    console.log(`missions = ${JSON.stringify(missions)}`);
    let id = missions[0].missionId;

    missionManager.moveMissionToFront(id,{windowMode : 101}).then(() => {
  	  console.log('moveMissionToFront is called ');
    });
  });

missionManager.moveMissionToFront

moveMissionToFront(missionId: number, options?: StartOptions): Promise<void>;

Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_MISSIONS

System capability: SystemCapability.Ability.AbilityRuntime.Mission

System API: This is a system API and cannot be called by third-party applications.

Parameters

Name Type Mandatory Description
missionId number Yes Mission ID.
options StartOptions No Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

  import missionManager from '@ohos.application.missionManager';
  import { BusinessError } from '@ohos.base';

  let id: number = -1;
  missionManager.getMissionInfos('',10).then((res) => {
    let allMissions = res;
    console.log(`size = ${allMissions.length}`);
    console.log(`missions = ${JSON.stringify(allMissions)}`);
    id = allMissions[0].missionId;
  }).catch((error: BusinessError) => {
      console.error(`getMissionInfos fail, error: ${error}`);
  });

  missionManager.moveMissionToFront(id).catch((error: BusinessError) => {
    console.error(`moveMissionToFront fail, error: ${error}`);
  });

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞