1# @ohos.resourceschedule.backgroundTaskManager (后台任务管理) 2 3本模块提供申请后台任务的接口。当应用退至后台时,开发者可以通过本模块接口为应用申请短时、长时任务,避免应用进程被终止或挂起。 4 5> **说明:** 6> 7> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9 10## 导入模块 11 12```ts 13import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; 14``` 15 16## backgroundTaskManager.requestSuspendDelay 17 18requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspendInfo 19 20申请短时任务。 21 22> **说明:** 23> 24> 短时任务的申请时间最长为3分钟,[低电量](js-apis-battery-info.md)时最长为1分钟。 25 26**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask 27 28**参数**: 29 30| 参数名 | 类型 | 必填 | 说明 | 31| -------- | -------------------- | ---- | ------------------------------ | 32| reason | string | 是 | 申请短时任务的原因。 | 33| callback | Callback<void> | 是 | 短时任务即将超时的回调函数,一般在超时前6秒,通过此回调通知应用。 | 34 35**返回值**: 36 37| 类型 | 说明 | 38| ------------------------------------- | --------- | 39| [DelaySuspendInfo](#delaysuspendinfo) | 返回短时任务信息。 | 40 41**错误码**: 42 43以下错误码的详细介绍请参见[backgroundTaskManager错误码](../errorcodes/errorcode-backgroundTaskMgr.md)。 44 45| 错误码ID | 错误信息 | 46| ---- | --------------------- | 47| 9800001 | Memory operation failed. | 48| 9800002 | Parcel operation failed. | 49| 9800003 | Inner transact failed. | | 50| 9800004 | System service operation failed. | 51| 9900001 | Caller information verification failed. | 52| 9900002 | Background task verification failed. | 53 54**示例**: 55 56```ts 57import { BusinessError } from '@ohos.base'; 58 59let myReason = 'test requestSuspendDelay'; 60try { 61 let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => { 62 console.info("Request suspension delay will time out."); 63 }) 64 let id = delayInfo.requestId; 65 let time = delayInfo.actualDelayTime; 66 console.info("The requestId is: " + id); 67 console.info("The actualDelayTime is: " + time); 68} catch (error) { 69 console.error(`requestSuspendDelay failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); 70} 71``` 72 73 74## backgroundTaskManager.getRemainingDelayTime 75 76getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>): void 77 78获取本次短时任务的剩余时间,使用callback异步回调。 79 80**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask 81 82**参数**: 83 84| 参数名 | 类型 | 必填 | 说明 | 85| --------- | --------------------------- | ---- | ---------------------------------------- | 86| requestId | number | 是 | 短时任务的请求ID。 | 87| callback | AsyncCallback<number> | 是 | 回调函数,返回本次短时任务的剩余时间,单位为毫秒。 | 88 89**错误码**: 90 91以下错误码的详细介绍请参见[backgroundTaskManager错误码](../errorcodes/errorcode-backgroundTaskMgr.md)。 92 93| 错误码ID | 错误信息 | 94| ---- | --------------------- | 95| 9800001 | Memory operation failed. | 96| 9800002 | Parcel operation failed. | 97| 9800003 | Inner transact failed. | 98| 9800004 | System service operation failed. | 99| 9900001 | Caller information verification failed. | 100| 9900002 | Background task verification failed. | 101 102 103**示例**: 104 105```ts 106import { BusinessError } from '@ohos.base'; 107 108let id = 1; 109backgroundTaskManager.getRemainingDelayTime(id, (error: BusinessError, res: number) => { 110 if(error) { 111 console.error(`callback => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`); 112 } else { 113 console.log('callback => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); 114 } 115}) 116``` 117 118 119## backgroundTaskManager.getRemainingDelayTime 120 121getRemainingDelayTime(requestId: number): Promise<number> 122 123获取本次短时任务的剩余时间,使用promise异步回调。 124 125**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask 126 127**参数**: 128 129| 参数名 | 类型 | 必填 | 说明 | 130| --------- | ------ | ---- | ---------- | 131| requestId | number | 是 | 短时任务的请求ID。 | 132 133**返回值**: 134 135| 类型 | 说明 | 136| --------------------- | ---------------------------------------- | 137| Promise<number> | Promise对象,返回本次短时任务的剩余时间,单位为毫秒。 | 138 139**错误码**: 140 141以下错误码的详细介绍请参见[backgroundTaskManager错误码](../errorcodes/errorcode-backgroundTaskMgr.md)。 142 143| 错误码ID | 错误信息 | 144| ---- | --------------------- | 145| 9800001 | Memory operation failed. | 146| 9800002 | Parcel operation failed. | 147| 9800003 | Inner transact failed. | | 148| 9800004 | System service operation failed. | 149| 9900001 | Caller information verification failed. | 150| 9900002 | Background task verification failed. | 151 152**示例**: 153 154```ts 155import { BusinessError } from '@ohos.base'; 156 157let id = 1; 158backgroundTaskManager.getRemainingDelayTime(id).then((res: number) => { 159 console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); 160}).catch((error: BusinessError) => { 161 console.error(`promise => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`); 162}) 163``` 164 165 166## backgroundTaskManager.cancelSuspendDelay 167 168cancelSuspendDelay(requestId: number): void 169 170取消短时任务。 171 172**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask 173 174**参数**: 175 176| 参数名 | 类型 | 必填 | 说明 | 177| --------- | ------ | ---- | ---------- | 178| requestId | number | 是 | 短时任务的请求ID。 | 179 180**错误码**: 181 182以下错误码的详细介绍请参见[backgroundTaskManager错误码](../errorcodes/errorcode-backgroundTaskMgr.md)。 183 184| 错误码ID | 错误信息 | 185| ---- | --------------------- | 186| 9800001 | Memory operation failed. | 187| 9800002 | Parcel operation failed. | 188| 9800003 | Inner transact failed. | | 189| 9800004 | System service operation failed. | 190| 9900001 | Caller information verification failed. | 191| 9900002 | Background task verification failed. | 192 193**示例**: 194 195 ```js 196 import { BusinessError } from '@ohos.base'; 197 198 let id = 1; 199 try { 200 backgroundTaskManager.cancelSuspendDelay(id); 201 } catch (error) { 202 console.error(`cancelSuspendDelay failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); 203 } 204 ``` 205 206## backgroundTaskManager.startBackgroundRunning 207 208startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback<void>): void 209 210申请长时任务,使用callback异步回调。 211 212**需要权限:** ohos.permission.KEEP_BACKGROUND_RUNNING 213 214**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask 215 216**参数**: 217 218| 参数名 | 类型 | 必填 | 说明 | 219| --------- | ---------------------------------- | ---- | ---------------------------------------- | 220| context | Context | 是 | 应用运行的上下文。<br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-context.md)。 | 221| bgMode | [BackgroundMode](#backgroundmode) | 是 | 长时任务模式。 | 222| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | 是 | 通知参数,用于指定点击长时任务通知后跳转的界面。 | 223| callback | AsyncCallback<void> | 是 | 回调函数,申请长时任务成功时,err为undefined,否则为错误对象。 | 224 225**错误码**: 226 227以下错误码的详细介绍请参见[backgroundTaskManager错误码](../errorcodes/errorcode-backgroundTaskMgr.md)。 228 229| 错误码ID | 错误信息 | 230| ---- | --------------------- | 231| 9800001 | Memory operation failed. | 232| 9800002 | Parcel operation failed. | 233| 9800003 | Inner transact failed. | | 234| 9800004 | System service operation failed. | 235| 9800005 | Background task verification failed. | 236| 9800006 | Notification verification failed. | 237| 9800007 | Task storage failed. | 238 239**示例**: 240 241```js 242import UIAbility from '@ohos.app.ability.UIAbility'; 243import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; 244import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent'; 245import Want from '@ohos.app.ability.Want'; 246import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 247import { BusinessError } from '@ohos.base'; 248 249function callback(error: BusinessError, data: void) { 250 if (error) { 251 console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); 252 } else { 253 console.info("Operation startBackgroundRunning succeeded"); 254 } 255} 256 257export default class EntryAbility extends UIAbility { 258 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 259 let wantAgentInfo: wantAgent.WantAgentInfo = { 260 // 点击通知后,将要执行的动作列表 261 wants: [ 262 { 263 bundleName: "com.example.myapplication", 264 abilityName: "EntryAbility" 265 } 266 ], 267 // 点击通知后,动作类型 268 operationType: wantAgent.OperationType.START_ABILITY, 269 // 使用者自定义的一个私有值 270 requestCode: 0, 271 // 点击通知后,动作执行属性 272 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 273 }; 274 275 try { 276 // 通过wantAgent模块下getWantAgent方法获取WantAgent对象 277 wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => { 278 try { 279 backgroundTaskManager.startBackgroundRunning(this.context, 280 backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback) 281 } catch (error) { 282 console.error(`Operation startBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); 283 } 284 }); 285 } catch (error) { 286 console.error(`Operation getWantAgent failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); 287 } 288 } 289}; 290``` 291 292## backgroundTaskManager.startBackgroundRunning 293 294startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise<void> 295 296申请长时任务,使用promise异步回调。 297 298**需要权限:** ohos.permission.KEEP_BACKGROUND_RUNNING 299 300**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask 301 302**参数**: 303 304| 参数名 | 类型 | 必填 | 说明 | 305| --------- | ---------------------------------- | ---- | ---------------------------------------- | 306| context | Context | 是 | 应用运行的上下文。<br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-context.md)。 | 307| bgMode | [BackgroundMode](#backgroundmode) | 是 | 长时任务模式。 | 308| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | 是 | 通知参数,用于指定点击长时任务通知后跳转的界面。 | 309 310**返回值**: 311 312| 类型 | 说明 | 313| -------------- | ---------------- | 314| Promise\<void> | 无返回结果的Promise对象。 | 315 316**错误码**: 317 318以下错误码的详细介绍请参见[backgroundTaskManager错误码](../errorcodes/errorcode-backgroundTaskMgr.md)。 319 320| 错误码ID | 错误信息 | 321| ---- | --------------------- | 322| 9800001 | Memory operation failed. | 323| 9800002 | Parcel operation failed. | 324| 9800003 | Inner transact failed. | | 325| 9800004 | System service operation failed. | 326| 9800005 | Background task verification failed. | 327| 9800006 | Notification verification failed. | 328| 9800007 | Task storage failed. | 329 330**示例**: 331 332```js 333import UIAbility from '@ohos.app.ability.UIAbility'; 334import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; 335import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent'; 336import Want from '@ohos.app.ability.Want'; 337import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 338import { BusinessError } from '@ohos.base'; 339 340export default class EntryAbility extends UIAbility { 341 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 342 let wantAgentInfo: wantAgent.WantAgentInfo = { 343 // 点击通知后,将要执行的动作列表 344 wants: [ 345 { 346 bundleName: "com.example.myapplication", 347 abilityName: "EntryAbility" 348 } 349 ], 350 // 点击通知后,动作类型 351 operationType: wantAgent.OperationType.START_ABILITY, 352 // 使用者自定义的一个私有值 353 requestCode: 0, 354 // 点击通知后,动作执行属性 355 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 356 }; 357 358 try { 359 // 通过wantAgent模块下getWantAgent方法获取WantAgent对象 360 wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => { 361 try { 362 backgroundTaskManager.startBackgroundRunning(this.context, 363 backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => { 364 console.info("Operation startBackgroundRunning succeeded"); 365 }).catch((error: BusinessError) => { 366 console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); 367 }); 368 } catch (error) { 369 console.error(`Operation startBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); 370 } 371 }); 372 } catch (error) { 373 console.error(`Operation getWantAgent failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); 374 } 375 } 376}; 377``` 378 379## backgroundTaskManager.stopBackgroundRunning 380 381stopBackgroundRunning(context: Context, callback: AsyncCallback<void>): void 382 383取消长时任务,使用callback异步回调。 384 385**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask 386 387**参数**: 388 389| 参数名 | 类型 | 必填 | 说明 | 390| -------- | ------------------------- | ---- | ---------------------------------------- | 391| context | Context | 是 | 应用运行的上下文。<br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-context.md)。 | 392| callback | AsyncCallback<void> | 是 | 回调函数,取消长时任务成功时,err为undefined,否则为错误对象。| 393 394**错误码**: 395 396以下错误码的详细介绍请参见[backgroundTaskManager错误码](../errorcodes/errorcode-backgroundTaskMgr.md)。 397 398| 错误码ID | 错误信息 | 399| ---- | --------------------- | 400| 9800001 | Memory operation failed. | 401| 9800002 | Parcel operation failed. | 402| 9800003 | Inner transact failed. | | 403| 9800004 | System service operation failed. | 404| 9800005 | Background task verification failed. | 405| 9800006 | Notification verification failed. | 406| 9800007 | Task storage failed. | 407 408**示例**: 409 410```js 411import UIAbility from '@ohos.app.ability.UIAbility'; 412import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; 413import Want from '@ohos.app.ability.Want'; 414import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 415import { BusinessError } from '@ohos.base'; 416 417function callback(error: BusinessError, data: void) { 418 if (error) { 419 console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); 420 } else { 421 console.info("Operation stopBackgroundRunning succeeded"); 422 } 423} 424 425export default class EntryAbility extends UIAbility { 426 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 427 try { 428 backgroundTaskManager.stopBackgroundRunning(this.context, callback); 429 } catch (error) { 430 console.error(`Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); 431 } 432 } 433}; 434``` 435 436## backgroundTaskManager.stopBackgroundRunning 437 438stopBackgroundRunning(context: Context): Promise<void> 439 440取消长时任务,使用promise异步回调。 441 442**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask 443 444**参数**: 445 446| 参数名 | 类型 | 必填 | 说明 | 447| ------- | ------- | ---- | ---------------------------------------- | 448| context | Context | 是 | 应用运行的上下文。<br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-context.md)。 | 449 450**返回值**: 451 452| 类型 | 说明 | 453| -------------- | ---------------- | 454| Promise\<void> | 无返回结果的Promise对象。 | 455 456**错误码**: 457 458以下错误码的详细介绍请参见[backgroundTaskManager错误码](../errorcodes/errorcode-backgroundTaskMgr.md)。 459 460| 错误码ID | 错误信息 | 461| ---- | --------------------- | 462| 9800001 | Memory operation failed. | 463| 9800002 | Parcel operation failed. | 464| 9800003 | Inner transact failed. | | 465| 9800004 | System service operation failed. | 466| 9800005 | Background task verification failed. | 467| 9800006 | Notification verification failed. | 468| 9800007 | Task storage failed. | 469 470**示例**: 471 472```js 473import UIAbility from '@ohos.app.ability.UIAbility'; 474import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; 475import Want from '@ohos.app.ability.Want'; 476import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 477import { BusinessError } from '@ohos.base'; 478 479export default class EntryAbility extends UIAbility { 480 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 481 try { 482 backgroundTaskManager.stopBackgroundRunning(this.context).then(() => { 483 console.info("Operation stopBackgroundRunning succeeded"); 484 }).catch((error: BusinessError) => { 485 console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); 486 }); 487 } catch (error) { 488 console.error(`Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); 489 } 490 } 491}; 492``` 493 494## backgroundTaskManager.applyEfficiencyResources 495 496applyEfficiencyResources(request: EfficiencyResourcesRequest): void 497 498申请能效资源。 499 500**系统能力**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply 501 502**系统API**: 此接口为系统接口。 503 504**参数**: 505 506| 参数名 | 类型 | 必填 | 说明 | 507| ------- | ------- | ---- | ---------------------------------------- | 508| request | [EfficiencyResourcesRequest](#efficiencyresourcesrequest) | 是 | 请求的必要信息,包括资源类型、超时时间等。 | 509 510 511**错误码**: 512 513以下错误码的详细介绍请参见[backgroundTaskManager错误码](../errorcodes/errorcode-backgroundTaskMgr.md)。 514 515| 错误码ID | 错误信息 | 516| ---- | --------------------- | 517| 9800001 | Memory operation failed. | 518| 9800002 | Parcel operation failed. | 519| 9800003 | Inner transact failed. | | 520| 9800004 | System service operation failed. | 521| 18700001 | Caller information verification failed. | 522 523**示例**: 524 525```js 526import { BusinessError } from '@ohos.base'; 527 528let request: backgroundTaskManager.EfficiencyResourcesRequest = { 529 resourceTypes: backgroundTaskManager.ResourceType.CPU, 530 isApply: true, 531 timeOut: 0, 532 reason: "apply", 533 isPersist: true, 534 isProcess: false, 535}; 536try { 537 backgroundTaskManager.applyEfficiencyResources(request); 538 console.info("applyEfficiencyResources success. "); 539} catch (error) { 540 console.error(`applyEfficiencyResources failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); 541} 542``` 543 544## backgroundTaskManager.resetAllEfficiencyResources 545 546resetAllEfficiencyResources(): void 547 548释放已申请的全部能效资源。 549 550**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply 551 552**系统API**: 此接口为系统接口。 553 554**错误码**: 555 556以下错误码的详细介绍请参见[backgroundTaskManager错误码](../errorcodes/errorcode-backgroundTaskMgr.md)。 557 558| 错误码ID | 错误信息 | 559| ---- | --------------------- | 560| 9800001 | Memory operation failed. | 561| 9800002 | Parcel operation failed. | 562| 9800003 | Inner transact failed. | | 563| 9800004 | System service operation failed. | 564| 18700001 | Caller information verification failed. | 565 566**示例**: 567 568```js 569import { BusinessError } from '@ohos.base'; 570 571try { 572 backgroundTaskManager.resetAllEfficiencyResources(); 573} catch (error) { 574 console.error(`resetAllEfficiencyResources failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); 575} 576``` 577 578## DelaySuspendInfo 579 580短时任务信息。 581 582**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask 583 584| 名称 | 类型 | 必填 | 说明 | 585| --------------- | ------ | ---- | ---------------------------------------- | 586| requestId | number | 是 | 短时任务的请求ID。 | 587| actualDelayTime | number | 是 | 应用实际申请的短时任务时间,单位为毫秒。<br/>短时任务申请时间最长为3分钟,[低电量](js-apis-battery-info.md)时最长为1分钟。 | 588 589## BackgroundMode 590 591长时任务模式。 592 593**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask 594 595| 名称 | 值 | 说明 | 596| ----------------------- | ---- | --------------------- | 597| DATA_TRANSFER | 1 | 数据传输。 | 598| AUDIO_PLAYBACK | 2 | 音频播放。 | 599| AUDIO_RECORDING | 3 | 录音。 | 600| LOCATION | 4 | 定位导航。 | 601| BLUETOOTH_INTERACTION | 5 | 蓝牙相关。 | 602| MULTI_DEVICE_CONNECTION | 6 | 多设备互联。 | 603| WIFI_INTERACTION | 7 | WLAN相关。<br>**系统API**: 此接口为系统接口。 | 604| VOIP | 8 | 音视频通话。<br>**系统API**: 此接口为系统接口。 | 605| TASK_KEEPING | 9 | 计算任务(仅对特定设备开放)。 | 606 607## EfficiencyResourcesRequest 608 609能效资源申请参数。 610 611**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply 612 613**系统API**: 此接口为系统接口。 614 615| 名称 | 类型 | 必填 | 说明 | 616| --------------- | ------ | ---- | ---------------------------------------- | 617| resourceTypes | number | 是 | 申请的资源类型。 | 618| isApply | boolean | 是 | 申请或释放资源。<br>- true表示申请资源,false表示释放部分资源。 | 619| timeOut | number | 是 | 资源使用时间,单位为毫秒。 | 620| isPersist | boolean | 否 | 是否永久持有资源,默认为false。<br>- true表示永久持有,false表示有限时间内持有。| 621| isProcess | boolean | 否 | 进程或应用申请,默认为false。<br>- true表示进程申请,false表示应用申请。 | 622| reason | string | 是 | 申请资源原因。 | 623 624## ResourceType 625 626能效资源类型。 627 628**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply 629 630**系统API**: 此接口为系统接口。 631 632| 名称 | 值 | 说明 | 633| ----------------------- | ---- | --------------------- | 634| CPU | 1 | CPU资源,申请后应用进程不被挂起。 | 635| COMMON_EVENT | 2 | 公共事件资源,申请后应用进程被挂起后,可以收到公共事件。 | 636| TIMER | 4 | 计时器,申请后应用进程被挂起后,Timer仍然可以唤醒应用。 | 637| WORK_SCHEDULER | 8 | 延迟任务资源,申请后延迟任务管控变宽松。 | 638| BLUETOOTH | 16 | 蓝牙资源,申请后应用进程被挂起后,蓝牙相关事件仍然可以唤醒应用。 | 639| GPS | 32 | GPS资源,申请后应用进程被挂起后,GPS相关事件可以唤醒应用。 | 640| AUDIO | 64 | 音频资源,有音频播放时对应的应用进程不被挂起。 | 641| RUNNING_LOCK<sup>10+</sup> | 128 | RUNNING_LOCK资源,申请后挂起状态不会代理RUNNING_BACKGROUND锁。 | 642| SENSOR<sup>10+</sup> | 256 | 申请后不拦截Sensor回调。 | 643