• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.appstartup.StartupConfigEntry (启动框架配置)
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @yzkp-->
5<!--Designer: @yzkp-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8
9
10本模块提供应用启动框架配置的能力。
11
12> **说明:**
13>
14> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
15>
16> 本模块接口仅可在Stage模型下使用。
17
18## 导入模块
19
20```ts
21import { StartupConfigEntry } from '@kit.AbilityKit';
22```
23
24## StartupConfigEntry.onConfig
25
26onConfig?(): StartupConfig
27
28应用启动时调用以配置应用启动框架的设置。
29
30**系统能力**:SystemCapability.Ability.AppStartup
31
32**返回值:**
33
34| 类型 | 说明 |
35| -------- | -------- |
36| StartupConfig | 启动框架配置。 |
37
38**示例:**
39
40```ts
41import { StartupConfig, StartupConfigEntry, StartupListener } from '@kit.AbilityKit';
42import { BusinessError } from '@kit.BasicServicesKit';
43import { hilog } from '@kit.PerformanceAnalysisKit';
44
45export default class MyStartupConfigEntry extends StartupConfigEntry {
46  onConfig() {
47    hilog.info(0x0000, 'testTag', `onConfig`);
48    let onCompletedCallback = (error: BusinessError<void>) => {
49      hilog.info(0x0000, 'testTag', `onCompletedCallback`);
50      if (error) {
51        hilog.info(0x0000, 'testTag', 'onCompletedCallback: %{public}d, message: %{public}s', error.code, error.message);
52      } else {
53        hilog.info(0x0000, 'testTag', `onCompletedCallback: success.`);
54      }
55    }
56    let startupListener: StartupListener = {
57      'onCompleted': onCompletedCallback
58    }
59    let config: StartupConfig = {
60      'timeoutMs': 10000,
61      'startupListener': startupListener
62    }
63    return config;
64  }
65}
66```
67
68## StartupConfigEntry.onRequestCustomMatchRule<sup>20+</sup>
69
70onRequestCustomMatchRule(want: Want): string
71
72应用启动时,启动框架会调用此接口获取自定义匹配规则。可以根据传入Want中的不同参数来返回不同的自定义规则值,并与启动任务配置的matchRules中customization字段进行匹配。若匹配成功,任务将在自动模式执行。当一个启动场景无法通过uri、action或意图名称规则来匹配启动任务时,可以使用本接口对匹配规则进一步细化。详细说明请参考[添加任务匹配规则](../../application-models/app-startup.md#添加任务匹配规则)章节。
73
74**系统能力**:SystemCapability.Ability.AppStartup
75
76**参数:**
77
78| 参数名 | 类型 | 必填 | 说明 |
79| -------- | -------- | -------- | -------- |
80| want | [Want](js-apis-app-ability-want.md) | 是 | 启动UIAbility的Want信息。 |
81
82**返回值:**
83
84| 类型 | 说明 |
85| -------- | -------- |
86| string | 返回自定义匹配规则值,用于匹配启动任务是否自动执行。 |
87
88**示例:**
89
90```ts
91import { StartupConfig, StartupConfigEntry, StartupListener, Want } from '@kit.AbilityKit';
92import { BusinessError } from '@kit.BasicServicesKit';
93import { hilog } from '@kit.PerformanceAnalysisKit';
94
95export default class MyStartupConfigEntry extends StartupConfigEntry {
96
97  // ...
98
99  onRequestCustomMatchRule(want: Want): string {
100    if (want?.parameters?.customParam == 'param1') {
101      return 'customRule1';
102    }
103    return '';
104  }
105}
106```