# 拦截页跳转至管控应用

## 场景介绍

Screen Time Guard Kit支持用户通过被管控应用拦截页跳转至当前管控应用，管理当前的管控策略。从26.0.0版本开始，Screen Time Guard Kit新增支持跳转时want参数携带当前管控策略相关信息。

## 用户体验设计

![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/f8/v3/tBeHjePfTKq1z1l-qb-E3Q/zh-cn_image_0000002747292005.png?HW-CC-KV=V1&HW-CC-Date=20260909T132941Z&HW-CC-Expire=31536000000&HW-CC-Sign=E78A3B2EDA773FE6CE1A963F5B1A55A3D0C160C4D0F19EA1CDC3FBB8C0A0301B)

## 业务流程

![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/ef/v3/wXJvA2bVQiuQqgs7RV-jYg/zh-cn_image_0000002717612056.png?HW-CC-KV=V1&HW-CC-Date=20260909T132941Z&HW-CC-Expire=31536000000&HW-CC-Sign=1A590BB9F2FE4AF10D8CA19514C71767C5507371A45F5A09163EF0D9CD29F794)

流程说明：

1. 应用的某一管控规则生效，导致被管控应用不可用时，用户点击被管控应用，健康使用设备会拉起该应用的拦截页面。

2. 用户点击拦截页面下方跳转按钮，健康使用设备查询被管控应用的token和对被管控应用生效的规则，将规则相关信息写入want自定义参数中。

3. 健康使用设备调用[startAbility](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-inner-application-uiabilitycontext#startability)接口拉起管控应用，传递的want参数携带当前管控规则相关信息。

4. 应用可以在入口Ability的[onCreate](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-app-ability-uiability#oncreate)和[onNewWant](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-app-ability-uiability#onnewwant)回调中接收并解析want参数，获取被管控应用的token、正在生效的管控规则名称等信息。

## 参数说明

want自定义参数如下表所示：

|参数名|类型|描述|
|:-------------------|:-------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|token|string|被管控应用的token。|
|strategyNames|string[]|当前对被管控应用生效的策略名称。 若有多个时间守护策略对该应用进行管控，则返回对应的策略名称数组。|
|isSetAppsRestriction|boolean|正在生效的规则是否包含[应用访问限制](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/screentimeguard-set-apps-restriction)。 true: 正在生效的规则包含应用访问限制，应用访问限制规则名称不会体现在strategyNames参数中。 false: 正在生效的规则不包含应用访问限制。|

## 开发前提

拦截页跳转至管控应用并携带管控规则相关信息需要申请用户授权，请先参考[请求用户授权](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/screentimeguard-request-user-auth)章节完成用户授权。

## 拦截页跳转至管控应用并携带管控规则相关信息

1. 导入相关模块。

   ```TypeScript
   import { UIAbility, Want } from '@kit.AbilityKit';
   import { hilog } from '@kit.PerformanceAnalysisKit';
   import { window } from '@kit.ArkUI';
   import Utils from '../utils/Utils';
   ```

2. 在onCreate和onNewWant回调中接收并解析want参数，获取当前管控规则相关信息。

   ```TypeScript
   export default class EntryAbility extends UIAbility {

     // 当UIAbility实例创建完成时，系统会触发该回调
     onCreate(want: Want): void {
       hilog.info(0x0000, 'GuardService', 'onCreate');
       let token: string = want.parameters?.['token'] as string;
       if (token !== undefined) {
         hilog.info(0x0000, 'GuardService', `Token: ${token}`);
       }
       let strategyNames: string[] = want.parameters?.['strategyNames'] as string[];
       if (strategyNames !== undefined) {
         hilog.info(0x0000, 'GuardService', `StrategyNames: ${strategyNames}`);
       }
       let isSetAppsRestriction: boolean = want.parameters?.['isSetAppsRestriction'] as boolean;
       if (isSetAppsRestriction !== undefined) {
         hilog.info(0x0000, 'GuardService', `IsSetAppsRestriction: ${isSetAppsRestriction}`);
       }
     }

     // ...

     // 当已经启动的UIAbility实例再次被拉起时，系统会触发该回调
     onNewWant(want: Want): void {
       hilog.info(0x0000, 'GuardService', 'onNewWant');
       let token: string = want.parameters?.['token'] as string;
       if (token !== undefined) {
         hilog.info(0x0000, 'GuardService', `Token: ${token}`);
       }
       let strategyNames: string[] = want.parameters?.['strategyNames'] as string[];
       if (strategyNames !== undefined) {
         hilog.info(0x0000, 'GuardService', `StrategyNames: ${strategyNames}`);
       }
       let isSetAppsRestriction: boolean = want.parameters?.['isSetAppsRestriction'] as boolean;
       if (isSetAppsRestriction !== undefined) {
         hilog.info(0x0000, 'GuardService', `IsSetAppsRestriction: ${isSetAppsRestriction}`);
       }
     }

     // ...
   }
   ```

