diff --git a/zh-cn/application-dev/reference/apis/js-apis-app-ability-missionManager.md b/zh-cn/application-dev/reference/apis/js-apis-app-ability-missionManager.md index fad982da3616da3355b5f28538cc36663db829ce..bcb46120dba1dc2ab2414246106d1dadddf70f0c 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-app-ability-missionManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-app-ability-missionManager.md @@ -20,7 +20,7 @@ ohos.permission.MANAGE_MISSIONS on(type:"mission", listener: MissionListener): number; -注册系统任务状态监听。 +注册系统任务状态监听器。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -32,13 +32,13 @@ on(type:"mission", listener: MissionListener): number; | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | - | listener | MissionListener | 是 | 系统任务监听方法。 | + | listener | MissionListener | 是 | 系统任务监听器。 | **返回值:** | 类型 | 说明 | | -------- | -------- | - | number | 监听方法的index值,由系统创建,在注册系统任务状态监听时分配,和监听方法一一对应 。 | + | number | 监听器的index值,由系统创建,在注册系统任务状态监听时分配,和监听器一一对应 。 | **示例:** @@ -51,7 +51,8 @@ var listener = { onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")}, onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")}, onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")}, - onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")} + onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")}, + onMissionLabelUpdated: function (mission) {console.log("--------onMissionLabelUpdated-------")} }; var listenerId = -1; @@ -105,7 +106,7 @@ export default class MainAbility extends UIAbility { off(type: "mission", listenerId: number, callback: AsyncCallback<void>): void; -取消任务状态监听。 +解注册任务状态监听器。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -117,7 +118,7 @@ off(type: "mission", listenerId: number, callback: AsyncCallback<void>): v | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | - | listenerId | number | 是 | 系统任务状态监听方法的index值,和监听方法一一对应,由registerMissionListener方法返回。 | + | listenerId | number | 是 | 系统任务状态监器法的index值,和监听器一一对应,由on方法返回。 | | callback | AsyncCallback<void> | 是 | 执行结果回调函数。 | **示例:** @@ -131,7 +132,8 @@ var listener = { onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")}, onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")}, onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")}, - onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")} + onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")}, + onMissionLabelUpdated: function (mission) {console.log("--------onMissionLabelUpdated-------")} }; var listenerId = -1; @@ -185,7 +187,7 @@ export default class MainAbility extends UIAbility { off(type: "mission", listenerId: number): Promise<void>; -取消任务状态监听,以promise方式返回执行结果。 +解注册任务状态监听,以promise方式返回执行结果。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -197,7 +199,7 @@ off(type: "mission", listenerId: number): Promise<void>; | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | - | listenerId | number | 是 | 系统任务状态监听方法的index值,和监听方法一一对应,由registerMissionListener方法返回。 | + | listenerId | number | 是 | 系统任务状态监听器的index值,和监听器一一对应,由on方法返回。 | **返回值:** @@ -216,7 +218,8 @@ var listener = { onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")}, onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")}, onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")}, - onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")} + onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")}, + onMissionLabelUpdated: function (mission) {console.log("--------onMissionLabelUpdated-------")} }; var listenerId = -1; @@ -292,7 +295,12 @@ getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<M try { var allMissions=missionManager.getMissionInfos("",10).catch(function(err){console.log(err);}); missionManager.getMissionInfo("", allMissions[0].missionId, (error, mission) => { - console.log("getMissionInfo is called, error.code = " + error.code) + if (error.code) { + console.log("getMissionInfo failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } + console.log("mission.missionId = " + mission.missionId); console.log("mission.runningState = " + mission.runningState); console.log("mission.lockedState = " + mission.lockedState); @@ -369,7 +377,11 @@ getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback<Arr ```ts try { missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfo failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); }) @@ -442,14 +454,22 @@ getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback& ```ts try { missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; - missionManager.getMissionSnapShot("", id, (error, snapshot) => { - console.log("getMissionSnapShot is called, error.code = " + error.code); - console.log("bundleName = " + snapshot.ability.bundleName); + missionManager.getMissionSnapShot("", id, (err, snapshot) => { + if (err.code) { + console.log("getMissionInfos failed, err.code:" + JSON.stringify(err.code) + + "err.message:" + JSON.stringify(err.message)); + return; + } + console.log("bundleName = " + snapshot.ability.bundleName); }) }) } catch (paramError) { @@ -507,7 +527,7 @@ getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnaps getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback\): void; -使用给定的任务ID获取任务低分辨率快照。 +获取任务低分辨率快照。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -528,13 +548,21 @@ getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: A ```ts try { missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; missionManager.getLowResolutionMissionSnapShot("", id, (error, snapshot) => { - console.log("getLowResolutionMissionSnapShot is called, error.code = " + error.code); + if (error.code) { + console.log("getLowResolutionMissionSnapShot failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("bundleName = " + snapshot.ability.bundleName); }) }) @@ -548,7 +576,7 @@ getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: A getLowResolutionMissionSnapShot(deviceId: string, missionId: number): Promise\; -使用给定的任务ID获取任务低分辨率快照。 +获取任务低分辨率快照。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -614,7 +642,12 @@ lockMission(missionId: number, callback: AsyncCallback<void>): void; ```ts try { missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } + console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; @@ -698,7 +731,11 @@ unlockMission(missionId: number, callback: AsyncCallback<void>): void; ```ts try { missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; @@ -785,7 +822,11 @@ clearMission(missionId: number, callback: AsyncCallback<void>): void; ```ts try { missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; @@ -917,7 +958,11 @@ moveMissionToFront(missionId: number, callback: AsyncCallback<void>): void ```ts try { missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; @@ -957,7 +1002,11 @@ moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCall ```ts try { missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; diff --git a/zh-cn/application-dev/reference/apis/js-apis-application-missionManager.md b/zh-cn/application-dev/reference/apis/js-apis-application-missionManager.md index f5cc6343be1662b1f2916930683f02bc263936bb..deb071195ff0101ee49e8d7f15c73bc6373677f4 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-application-missionManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-application-missionManager.md @@ -20,7 +20,7 @@ ohos.permission.MANAGE_MISSIONS registerMissionListener(listener: MissionListener): number; -注册系统任务状态监听。 +注册系统任务状态监听器。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -32,13 +32,13 @@ registerMissionListener(listener: MissionListener): number; | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | - | listener | [MissionListener](js-apis-inner-application-missionListener.md) | 是 | 系统任务监听方法。 | + | listener | [MissionListener](js-apis-inner-application-missionListener.md) | 是 | 系统任务监听器。 | **返回值:** | 类型 | 说明 | | -------- | -------- | - | number | 监听方法的index值,由系统创建,在注册系统任务状态监听时分配,和监听方法一一对应 。 | + | number | 监听器的index值,由系统创建,在注册系统任务状态监听器时分配,和监听器一一对应 。 | **示例:** @@ -61,7 +61,7 @@ var listenerid = missionManager.registerMissionListener(listener); unregisterMissionListener(listenerId: number, callback: AsyncCallback<void>): void; -取消任务状态监听。 +解注册任务状态监听器。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -73,7 +73,7 @@ unregisterMissionListener(listenerId: number, callback: AsyncCallback<void> | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | - | listenerId | number | 是 | 系统任务状态监听方法的index值,和监听方法一一对应,由registerMissionListener方法返回。 | + | listenerId | number | 是 | 系统任务状态监听器的index值,和监听器一一对应,由registerMissionListener方法返回。 | | callback | AsyncCallback<void> | 是 | 执行结果回调函数。 | **示例:** @@ -101,7 +101,7 @@ unregisterMissionListener(listenerId: number, callback: AsyncCallback<void> unregisterMissionListener(listenerId: number): Promise<void>; -取消任务状态监听,以promise方式返回执行结果。 +反注册任务状态监听器,以promise方式返回执行结果。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -113,7 +113,7 @@ unregisterMissionListener(listenerId: number): Promise<void>; | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | - | listenerId | number | 是 | 系统任务状态监听方法的index值,和监听方法一一对应,由registerMissionListener方法返回。 | + | listenerId | number | 是 | 系统任务状态监听器的index值,和监听器一一对应,由registerMissionListener方法返回。 | **返回值:** @@ -146,7 +146,7 @@ unregisterMissionListener(listenerId: number): Promise<void>; getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<MissionInfo>): void; -获取任务信息,以异步回调的方式返回任务信息。 +获取单个任务信息,以异步回调的方式返回任务信息。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -169,7 +169,12 @@ getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<M var allMissions=missionManager.getMissionInfos("",10).catch(function(err){console.log(err);}); missionManager.getMissionInfo("", allMissions[0].missionId, (error, mission) => { - console.log("getMissionInfo is called, error.code = " + error.code) + if (error.code) { + console.log("getMissionInfo failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } + console.log("mission.missionId = " + mission.missionId); console.log("mission.runningState = " + mission.runningState); console.log("mission.lockedState = " + mission.lockedState); @@ -184,7 +189,7 @@ getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<M getMissionInfo(deviceId: string, missionId: number): Promise<MissionInfo>; -获取任务信息,以promise方式返回任务信息。 +获取单个任务信息,以promise方式返回任务信息。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -242,7 +247,11 @@ getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback<Arr import missionManager from '@ohos.application.missionManager' missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); }) @@ -311,14 +320,22 @@ getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback& import missionManager from '@ohos.application.missionManager' missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; missionManager.getMissionSnapShot("", id, (error, snapshot) => { - console.log("getMissionSnapShot is called, error.code = " + error.code); - console.log("bundleName = " + snapshot.ability.bundleName); + if (error.code) { + console.log("getMissionSnapShot failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } + console.log("bundleName = " + snapshot.ability.bundleName); }) }) ``` @@ -371,7 +388,7 @@ getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnaps getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback\): void; -使用给定的任务ID获取任务低分辨率快照。 +获取任务低分辨率快照。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -393,14 +410,22 @@ getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: A import missionManager from '@ohos.application.missionManager' missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; missionManager.getLowResolutionMissionSnapShot("", id, (error, snapshot) => { - console.log("getLowResolutionMissionSnapShot is called, error.code = " + error.code); - console.log("bundleName = " + snapshot.ability.bundleName); + if (error.code) { + console.log("getLowResolutionMissionSnapShot failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } + console.log("bundleName = " + snapshot.ability.bundleName); }) }) ``` @@ -410,7 +435,7 @@ getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: A getLowResolutionMissionSnapShot(deviceId: string, missionId: number): Promise\; -使用给定的任务ID获取任务低分辨率快照。 +获取任务低分辨率快照。 **需要权限**:ohos.permission.MANAGE_MISSIONS @@ -475,7 +500,11 @@ lockMission(missionId: number, callback: AsyncCallback<void>): void; import missionManager from '@ohos.application.missionManager' missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; @@ -554,7 +583,11 @@ unlockMission(missionId: number, callback: AsyncCallback<void>): void; import missionManager from '@ohos.application.missionManager' missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; @@ -637,7 +670,11 @@ clearMission(missionId: number, callback: AsyncCallback<void>): void; import missionManager from '@ohos.application.missionManager' missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; @@ -768,7 +805,11 @@ moveMissionToFront(missionId: number, callback: AsyncCallback<void>): void import missionManager from '@ohos.application.missionManager' missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; @@ -806,7 +847,11 @@ moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCall import missionManager from '@ohos.application.missionManager' missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } console.log("size = " + missions.length); console.log("missions = " + JSON.stringify(missions)); var id = missions[0].missionId; diff --git a/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionInfo.md b/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionInfo.md index 3f3fd0c235df03dd07fc5ccb5705675f8e1056e7..1558a06859d60d4302a217238c8d029143009b6f 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionInfo.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionInfo.md @@ -1,6 +1,6 @@ # MissionInfo -表示Ability对应的任务信息,可以通过[getMissionInfo](js-apis-app-ability-missionManager.md#missionmanagergetmissioninfo)获取。 +表示任务的详细信息,可以通过[getMissionInfo](js-apis-app-ability-missionManager.md#missionmanagergetmissioninfo)获取。 **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Mission @@ -19,16 +19,27 @@ **示例:** ```ts -import missionManager from '@ohos.application.missionManager' +import missionManager from '@ohos.app.ability.missionManager' -missionManager.getMissionInfo("12345", 1, (error, data) => { - console.info('getMissionInfo missionId is:' + JSON.stringify(data.missionId)); - console.info('getMissionInfo runningState is:' + JSON.stringify(data.runningState)); - console.info('getMissionInfo lockedState is:' + JSON.stringify(data.lockedState)); - console.info('getMissionInfo timestamp is:' + JSON.stringify(data.timestamp)); - console.info('getMissionInfo want is:' + JSON.stringify(data.want)); - console.info('getMissionInfo label is:' + JSON.stringify(data.label)); - console.info('getMissionInfo iconPath is:' + JSON.stringify(data.iconPath)); - console.info('getMissionInfo continuable is:' + JSON.stringify(data.continuable)); -}); +try { + missionManager.getMissionInfo("", 1, (error, data) => { + if (error.code) { + // 处理业务逻辑错误 + console.log("getMissionInfo failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } + + console.log('getMissionInfo missionId is:' + JSON.stringify(data.missionId)); + console.log('getMissionInfo runningState is:' + JSON.stringify(data.runningState)); + console.log('getMissionInfo lockedState is:' + JSON.stringify(data.lockedState)); + console.log('getMissionInfo timestamp is:' + JSON.stringify(data.timestamp)); + console.log('getMissionInfo want is:' + JSON.stringify(data.want)); + console.log('getMissionInfo label is:' + JSON.stringify(data.label)); + console.log('getMissionInfo iconPath is:' + JSON.stringify(data.iconPath)); + console.log('getMissionInfo continuable is:' + JSON.stringify(data.continuable)); + }); +} catch (paramError) { + console.log("error: " + paramError.code + ", " + paramError.message); +} ``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionListener.md b/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionListener.md index 6dbc6f9e7adf7335f834a3c75637869a9733ab0d..6cf445cbe310532951892f1785a3d5ee5cc7e426 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionListener.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionListener.md @@ -1,6 +1,6 @@ # MissionListener -定义系统任务状态监听,可以通过[registerMissionListener](js-apis-application-missionManager.md#missionmanagerregistermissionlistener)注册。 +定义系统任务状态监听,可以通过[on](js-apis-app-ability-missionManager.md#missionmanageron)注册。 **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Mission @@ -16,7 +16,7 @@ **示例:** ```ts -import missionManager from '@ohos.application.missionManager' +import missionManager from '@ohos.app.ability.missionManager' let listener = { onMissionCreated: function (mission) { @@ -38,5 +38,10 @@ let listener = { console.log("onMissionClosed mission: " + JSON.stringify(mission)); } }; -let listenerid = missionManager.registerMissionListener(listener); + +try { + let listenerId = missionManager.on("mission", listener); +} catch (paramError) { + console.log("error: " + paramError.code + ", " + paramError.message); +} ``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionSnapshot.md b/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionSnapshot.md index 6cfb665902e90388e9043432406e64996bfe9daf..2310755f6bc2fd5ac0720e75060152ce6b050588 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionSnapshot.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inner-application-missionSnapshot.md @@ -11,7 +11,7 @@ | 名称 | 类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | -| ability | ElementName | 是 | 是 | 表示Ability任务元素名称。 | +| ability | ElementName | 是 | 是 | 表示该任务的组件信息。 | | snapshot | [image.PixelMap](js-apis-image.md) | 是 | 是 | 表示任务快照。 | ## 使用说明 @@ -20,19 +20,33 @@ **示例:** ```ts -import ElementName from '@ohos.bundle'; -import image from '@ohos.multimedia.image'; -import missionManager from '@ohos.application.missionManager'; - -missionManager.getMissionInfos("", 10, (error, missions) => { - console.log("getMissionInfos is called, error.code = " + error.code); - console.log("size = " + missions.length); - console.log("missions = " + JSON.stringify(missions)); - var id = missions[0].missionId; - - missionManager.getMissionSnapShot("", id, (error, snapshot) => { - console.log("getMissionSnapShot is called, error.code = " + error.code); - console.log("bundleName = " + snapshot.ability.bundleName); - }) -}) + import ElementName from '@ohos.bundle'; + import image from '@ohos.multimedia.image'; + import missionManager from '@ohos.app.ability.missionManager'; + + try { + missionManager.getMissionInfos("", 10, (error, missions) => { + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) + + "error.message:" + JSON.stringify(error.message)); + return; + } + console.log("size = " + missions.length); + console.log("missions = " + JSON.stringify(missions)); + var id = missions[0].missionId; + + missionManager.getMissionSnapShot("", id, (err, snapshot) => { + if (err.code) { + console.log("getMissionInfos failed, err.code:" + JSON.stringify(err.code) + + "err.message:" + JSON.stringify(err.message)); + return; + } + + // 执行正常业务 + console.log("bundleName = " + snapshot.ability.bundleName); + }) + }) + } catch (paramError) { + console.log("error: " + paramError.code + ", " + paramError.message); + } ``` \ No newline at end of file