Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
f474d34d
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f474d34d
编写于
11月 04, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 04, 2022
浏览文件
操作
浏览文件
下载
差异文件
!10458 新增bundle.appControl文档
Merge pull request !10458 from xsz233/master
上级
34ee7c78
d7b4eda9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
394 addition
and
0 deletion
+394
-0
zh-cn/application-dev/reference/apis/js-apis-bundle-appControl.md
...plication-dev/reference/apis/js-apis-bundle-appControl.md
+394
-0
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-bundle-appControl.md
0 → 100644
浏览文件 @
f474d34d
# appControl模块
本模块提供应用拦截能力。对应用设置处置状态后,应用会被禁止运行;用户点击桌面图标时,会根据应用的处置状态,跳转到对应的页面。本模块支持对应用的处置状态进行设置、获取、删除。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
本模块接口为系统接口。
## 导入模块
```
ts
import
appControl
from
'
@ohos.bundle.appControl
'
```
## appControl.setDisposedStatus
setDisposedStatus(appId: string, disposedWant: Want): Promise
\<
void>
以异步方法设置应用的处置状态。使用Promise异步回调。成功返回null,失败返回对应错误信息。
**需要权限:**
ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:**
SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:**
此接口为系统接口,三方应用不支持调用。
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | 是 | 需要设置处置状态的应用的appId。
<br>
appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 |
| disposedWant | Want | 是 | 对应用的处置意图。 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------------ |
| Promise
\<
void> | Promise对象。无返回结果的Promise对象。 |
**错误码**
以下错误码的详细介绍请参见
[
ohos.bundle错误码
](
../errorcodes/errcode-bundle.md
)
。
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```
ts
import
appControl
from
'
@ohos.bundle.appControl
'
import
bundleManager
from
'
@ohos.bundle.bundleManager
'
;
// 获取appId
var
bundleName
=
'
com.example.myapplication
'
;
var
appId
;
try
{
bundleManager
.
getBundleInfo
(
bundleName
,
BundleManager
.
BundleFlags
.
GET_BUNDLE_INFO_WITH_SIGNATURE_INFO
)
.
then
((
data
)
=>
{
appId
=
data
.
signatureInfo
.
appId
;
},
error
=>
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
}
var
want
=
{
bundleName
:
'
com.example.myapplication
'
};
try
{
appControl
.
setDisposedStatus
(
appId
,
want
)
.
then
(()
=>
{
console
.
info
(
'
setDisposedStatus success
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
setDisposedStatus failed
'
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
'
setDisposedStatus failed
'
+
error
.
message
);
}
```
## appControl.setDisposedStatus
setDisposedStatus(appId: string, disposedWant: Want, callback: AsyncCallback
\<
void>): void;
以异步方法设置应用的处置状态。使用callback异步回调。成功返回null,失败返回对应错误信息。
**需要权限:**
ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:**
SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:**
此接口为系统接口,三方应用不支持调用
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------------------------------- | ---- | --------------------------------------- |
| appId | string | 是 | 需要设置处置的应用的appId
<br>
appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 |
| disposedWant | Want | 是 | 对应用的处置意图。 |
| callback | AsyncCallback
\<
void> | 是 | 回调函数,当设置处置状态成功,err为undefined,否则为错误对象。 |
**错误码**
以下错误码的详细介绍请参见
[
ohos.bundle错误码
](
../errorcodes/errcode-bundle.md
)
。
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```
ts
import
appControl
from
'
@ohos.bundle.appControl
'
import
bundleManager
from
'
@ohos.bundle.bundleManager
'
;
// 获取appId
var
bundleName
=
'
com.example.myapplication
'
;
var
appId
;
try
{
bundleManager
.
getBundleInfo
(
bundleName
,
BundleManager
.
BundleFlags
.
GET_BUNDLE_INFO_WITH_SIGNATURE_INFO
)
.
then
((
data
)
=>
{
appId
=
data
.
signatureInfo
.
appId
;
},
error
=>
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
}
var
want
=
{
bundleName
:
'
com.example.myapplication
'
};
try
{
appControl
.
setDisposedStatus
(
appId
,
want
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
setDisposedStatus failed
'
+
error
.
message
);
return
;
}
console
.
info
(
'
setDisposedStatus success
'
);
});
}
catch
(
error
)
{
console
.
error
(
'
setDisposedStatus failed
'
+
error
.
message
);
}
```
## appControl.getDisposedStatus
getDisposedStatus(appId: string): Promise
\<
Want>;
以异步方法获取指定应用已设置的处置状态。使用Promise异步回调,成功返回应用的处置状态,失败返回对应错误信息。
**需要权限:**
ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:**
SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:**
此接口为系统接口,三方应用不支持调用
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | 是 | 要查询的应用的appId
<br>
appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------------ |
| Promise
\<
Want> | Promise对象,返回应用的处置状态。 |
**错误码**
以下错误码的详细介绍请参见
[
ohos.bundle错误码
](
../errorcodes/errcode-bundle.md
)
。
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```
ts
import
appControl
from
'
@ohos.bundle.appControl
'
import
bundleManager
from
'
@ohos.bundle.bundleManager
'
;
// 获取appId
var
bundleName
=
'
com.example.myapplication
'
;
var
appId
;
try
{
bundleManager
.
getBundleInfo
(
bundleName
,
BundleManager
.
BundleFlags
.
GET_BUNDLE_INFO_WITH_SIGNATURE_INFO
)
.
then
((
data
)
=>
{
appId
=
data
.
signatureInfo
.
appId
;
},
error
=>
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
}
try
{
appControl
.
getDisposedStatus
(
appId
)
.
then
((
data
)
=>
{
console
.
info
(
'
getDisposedStatus success. DisposedStatus:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
getDisposedStatus failed
'
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
'
getDisposedStatus failed
'
+
error
.
message
);
}
```
## appControl.getDisposedStatus
getDisposedStatus(appId: string, callback: AsyncCallback
\<
Want>): void;
以异步方法获取指定应用的处置状态。使用callback异步回调,成功返回应用的处置状态,失败返回对应错误信息。
**需要权限:**
ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:**
SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:**
此接口为系统接口,三方应用不支持调用
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | 是 | 要查询的应用的appId
<br>
appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 |
| callback | AsyncCallback
\<
Want> | 是 | 回调函数。当获取应用的处置状态成功时,err为undefined,data为获取到的处置状态;否则为错误对象。 |
**错误码**
以下错误码的详细介绍请参见
[
ohos.bundle错误码
](
../errorcodes/errcode-bundle.md
)
。
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```
ts
import
appControl
from
'
@ohos.bundle.appControl
'
import
bundleManager
from
'
@ohos.bundle.bundleManager
'
;
// 获取appId
var
bundleName
=
'
com.example.myapplication
'
;
var
appId
;
try
{
bundleManager
.
getBundleInfo
(
bundleName
,
BundleManager
.
BundleFlags
.
GET_BUNDLE_INFO_WITH_SIGNATURE_INFO
)
.
then
((
data
)
=>
{
appId
=
data
.
signatureInfo
.
appId
;
},
error
=>
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
}
try
{
appControl
.
getDisposedStatus
(
appId
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
getDisposedStatus failed
'
+
error
.
message
);
return
;
}
console
.
info
(
'
getDisposedStatus success. DisposedStatus:
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
error
)
{
console
.
error
(
'
getDisposedStatus failed
'
+
error
.
message
);
}
```
## appControl.deleteDisposedStatus
deleteDisposedStatus(appId: string): Promise
\<
void>
以异步方法删除应用的处置状态。使用promise异步回调,成功返回null,失败返回对应错误信息。
**需要权限:**
ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:**
SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:**
此接口为系统接口,三方应用不支持调用
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | 是 | 要删除处置状态的应用的appId
<br>
appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 | |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------------ |
| Promise
\<
void> | Promise对象,无返回结果的Promise对象 |
**错误码**
以下错误码的详细介绍请参见
[
ohos.bundle错误码
](
../errorcodes/errcode-bundle.md
)
。
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```
ts
import
appControl
from
'
@ohos.bundle.appControl
'
import
bundleManager
from
'
@ohos.bundle.bundleManager
'
;
// 获取appId
var
bundleName
=
'
com.example.myapplication
'
;
var
appId
;
try
{
bundleManager
.
getBundleInfo
(
bundleName
,
BundleManager
.
BundleFlags
.
GET_BUNDLE_INFO_WITH_SIGNATURE_INFO
)
.
then
((
data
)
=>
{
appId
=
data
.
signatureInfo
.
appId
;
},
error
=>
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
}
try
{
appControl
.
deleteDisposedStatus
(
appId
)
.
then
(()
=>
{
console
.
info
(
'
deleteDisposedStatus success
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
deleteDisposedStatus failed
'
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
'
deleteDisposedStatus failed
'
+
error
.
message
);
}
```
## appControl.deleteDisposedStatus
deleteDisposedStatus(appId: string, callback: AsyncCallback
\<
void>) : void
以异步方法删除应用的处置状态。使用callback异步回调,成功返回null,失败返回对应错误信息。
**需要权限:**
ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:**
SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:**
此接口为系统接口,三方应用不支持调用
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | 是 | 要查询的应用的appId。
<br>
appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 |
| callback | AsyncCallback
\<
void> | 是 | 回调函数,当设置处置状态成功时,err返回undefined。否则回调函数返回具体错误对象。 |
**错误码**
以下错误码的详细介绍请参见
[
ohos.bundle错误码
](
../errorcodes/errcode-bundle.md
)
。
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```
ts
import
appControl
from
'
@ohos.bundle.appControl
'
import
bundleManager
from
'
@ohos.bundle.bundleManager
'
;
// 获取appId
var
bundleName
=
'
com.example.myapplication
'
;
var
appId
;
try
{
bundleManager
.
getBundleInfo
(
bundleName
,
BundleManager
.
BundleFlags
.
GET_BUNDLE_INFO_WITH_SIGNATURE_INFO
)
.
then
((
data
)
=>
{
appId
=
data
.
signatureInfo
.
appId
;
},
error
=>
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
"
getBundleInfo failed
"
+
error
.
message
);
}
try
{
appControl
.
deleteDisposedStatus
(
appId
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
deleteDisposedStatus failed
'
+
error
.
message
);
return
;
}
console
.
info
(
'
deleteDisposedStatus success
'
);
});
}
catch
(
error
)
{
console
.
error
(
'
deleteDisposedStatus failed
'
+
error
.
message
);
}
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录