未验证 提交 9dcee299 编写于 作者: L Lotol 提交者: Gitee

update zh-cn/application-dev/reference/apis/js-apis-defaultAppManager.md.

Signed-off-by: NLotol <linxiangzhi@huawei.com>
上级 0e430737
...@@ -99,6 +99,39 @@ defaultAppMgr.isDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err, ...@@ -99,6 +99,39 @@ defaultAppMgr.isDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err,
}); });
``` ```
## defaultAppMgr.isDefaultApplicationSync<sup>10+</sup>
isDefaultApplicationSync(type: string): boolean;
以同步方法根据系统已定义的应用类型判断当前应用是否是该应用类型的默认应用,使用boolean形式返回结果。
**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------| ------ | ---- | --------------------------------------- |
| type | string | 是 | 要查询的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值。 |
**返回值:**
| 类型 | 说明 |
| ------- | -------------------- |
| boolean | Promise形式返回当前应用是否是默认应用,true表示是默认应用,false表示不是默认应用。 |
**示例:**
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.isDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER)
.then((data) => {
console.info('Operation successful. IsDefaultApplicationSync ? ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
```
## defaultAppMgr.getDefaultApplication ## defaultAppMgr.getDefaultApplication
getDefaultApplication(type: string, userId?: number): Promise\<BundleInfo> getDefaultApplication(type: string, userId?: number): Promise\<BundleInfo>
...@@ -255,6 +288,63 @@ defaultAppMgr.getDefaultApplication("image/png", (err, data) => { ...@@ -255,6 +288,63 @@ defaultAppMgr.getDefaultApplication("image/png", (err, data) => {
}); });
``` ```
## defaultAppMgr.getDefaultApplicationSync<sup>10+</sup>
getDefaultApplicationSync(type: string, userId?: number): BundleInfo;
以同步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型获取默认应用信息,使用BundleInfo返回结果。
**需要权限:** ohos.permission.GET_DEFAULT_APPLICATION
**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
**系统API:** 此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------| ------ | ---- | --------------------------------------- |
| type | string | 是 | 要查询的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值,或者符合媒体类型格式的文件类型。|
| userId | number | 否 | 用户ID。默认值:调用方所在用户。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------ | -------------------- |
| [BundleInfo](js-apis-bundle-BundleInfo.md) | 返回的默认应用包信息。|
**错误码:**
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
| 错误码ID | 错误信息 |
| -------- | ----------------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700023 | The specified default app does not exist. |
| 17700025 | The specified type is invalid. |
**示例:**
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.getDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER)
.then((data) => {
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
defaultAppMgr.getDefaultApplicationSync("image/png")
.then((data) => {
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
```
## defaultAppMgr.setDefaultApplication ## defaultAppMgr.setDefaultApplication
setDefaultApplication(type: string, elementName: ElementName, userId?: number): Promise\<void> setDefaultApplication(type: string, elementName: ElementName, userId?: number): Promise\<void>
...@@ -446,11 +536,11 @@ defaultAppMgr.setDefaultApplication("image/png", { ...@@ -446,11 +536,11 @@ defaultAppMgr.setDefaultApplication("image/png", {
}); });
``` ```
## defaultAppMgr.resetDefaultApplication ## defaultAppMgr.setDefaultApplicationSync<sup>10+</sup>
resetDefaultApplication(type: string, userId?: number): Promise\<void> setDefaultApplicationSync(type: string, elementName: ElementName, userId?: number): void;
异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型重置默认应用,使用Promise形式返回结果 同步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型设置默认应用,返回undefined
**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION **需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
...@@ -462,45 +552,67 @@ resetDefaultApplication(type: string, userId?: number): Promise\<void> ...@@ -462,45 +552,67 @@ resetDefaultApplication(type: string, userId?: number): Promise\<void>
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | --------------------------------------- | | ----------- | ------ | ---- | --------------------------------------- |
| type | string | 是 | 要重置的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值,或者符合媒体类型格式的文件类型。 | | type | string | 是 | 要设置的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值,或者符合媒体类型格式的文件类型。|
| elementName | [ElementName](js-apis-bundle-ElementName.md) | 是 | 要设置为默认应用的组件信息。 |
| userId | number | 否 | 用户ID。默认值:调用方所在用户。 | | userId | number | 否 | 用户ID。默认值:调用方所在用户。 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------------------- |
| void | undefined对象,无返回结果的undefined对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md) 以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| -------- | ----------------------------------- | | -------- | ---------------------------------------------- |
| 17700004 | The specified user ID is not found. | | 17700004 | The specified user ID is not found. |
| 17700025 | The specified type is invalid. | | 17700025 | The specified type is invalid. |
| 17700028 | The specified ability does not match the type. |
**示例:** **示例:**
```ts ```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager'; import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.setDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, {
bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
}).then((data) => {
console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
let userId = 100; let userId = 100;
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId) defaultAppMgr.setDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, {
.then((data) => { bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
}, userId).then((data) => {
console.info('Operation successful.'); console.info('Operation successful.');
}) }).catch((error) => {
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error)); console.error('Operation failed. Cause: ' + JSON.stringify(error));
}); });
defaultAppMgr.resetDefaultApplication("image/png", userId) defaultAppMgr.setDefaultApplicationSync("image/png", {
.then((data) => { bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
}, userId).then((data) => {
console.info('Operation successful.'); console.info('Operation successful.');
}) }).catch((error) => {
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error)); console.error('Operation failed. Cause: ' + JSON.stringify(error));
}); });
``` ```
## defaultAppMgr.resetDefaultApplication ## defaultAppMgr.resetDefaultApplication
resetDefaultApplication(type: string, userId: number, callback: AsyncCallback\<void>) : void; resetDefaultApplication(type: string, userId?: number): Promise\<void>
以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型重置默认应用,使用callback形式返回结果。 以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型重置默认应用,使用Promise形式返回结果。
**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION **需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
...@@ -513,8 +625,7 @@ resetDefaultApplication(type: string, userId: number, callback: AsyncCallback\<v ...@@ -513,8 +625,7 @@ resetDefaultApplication(type: string, userId: number, callback: AsyncCallback\<v
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | --------------------------------------- | | ----------- | ------ | ---- | --------------------------------------- |
| type | string | 是 | 要重置的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值,或者符合媒体类型格式的文件类型。 | | type | string | 是 | 要重置的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值,或者符合媒体类型格式的文件类型。 |
| userId | number | 是 | 用户ID。 | | userId | number | 否 | 用户ID。默认值:调用方所在用户。 |
| callback | AsyncCallback\<void> | 是 | 程序启动作为入参的回调函数。 |
**错误码:** **错误码:**
...@@ -530,26 +641,26 @@ resetDefaultApplication(type: string, userId: number, callback: AsyncCallback\<v ...@@ -530,26 +641,26 @@ resetDefaultApplication(type: string, userId: number, callback: AsyncCallback\<v
```ts ```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager'; import defaultAppMgr from '@ohos.bundle.defaultAppManager';
let userId = 100; let userId = 100;
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId, (err, data) => { defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId)
if (err) { .then((data) => {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.'); console.info('Operation successful.');
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
}); });
defaultAppMgr.resetDefaultApplication("image/png", userId, (err, data) => { defaultAppMgr.resetDefaultApplication("image/png", userId)
if (err) { .then((data) => {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.'); console.info('Operation successful.');
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
}); });
``` ```
## defaultAppMgr.resetDefaultApplication ## defaultAppMgr.resetDefaultApplication
resetDefaultApplication(type: string, callback: AsyncCallback\<void>) : void; resetDefaultApplication(type: string, userId: number, callback: AsyncCallback\<void>) : void;
以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型重置默认应用,使用callback形式返回结果。 以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型重置默认应用,使用callback形式返回结果。
...@@ -564,6 +675,7 @@ resetDefaultApplication(type: string, callback: AsyncCallback\<void>) : void; ...@@ -564,6 +675,7 @@ resetDefaultApplication(type: string, callback: AsyncCallback\<void>) : void;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | --------------------------------------- | | ----------- | ------ | ---- | --------------------------------------- |
| type | string | 是 | 要重置的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值,或者符合媒体类型格式的文件类型。 | | type | string | 是 | 要重置的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值,或者符合媒体类型格式的文件类型。 |
| userId | number | 是 | 用户ID。 |
| callback | AsyncCallback\<void> | 是 | 程序启动作为入参的回调函数。 | | callback | AsyncCallback\<void> | 是 | 程序启动作为入参的回调函数。 |
**错误码:** **错误码:**
...@@ -572,13 +684,15 @@ resetDefaultApplication(type: string, callback: AsyncCallback\<void>) : void; ...@@ -572,13 +684,15 @@ resetDefaultApplication(type: string, callback: AsyncCallback\<void>) : void;
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| -------- | ----------------------------------- | | -------- | ----------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700025 | The specified type is invalid. | | 17700025 | The specified type is invalid. |
**示例:** **示例:**
```ts ```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager'; import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err, data) => { let userId = 100;
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId, (err, data) => {
if (err) { if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err)); console.error('Operation failed. Cause: ' + JSON.stringify(err));
return; return;
...@@ -586,7 +700,7 @@ defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (er ...@@ -586,7 +700,7 @@ defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (er
console.info('Operation successful.'); console.info('Operation successful.');
}); });
defaultAppMgr.resetDefaultApplication("image/png", (err, data) => { defaultAppMgr.resetDefaultApplication("image/png", userId, (err, data) => {
if (err) { if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err)); console.error('Operation failed. Cause: ' + JSON.stringify(err));
return; return;
...@@ -595,100 +709,11 @@ defaultAppMgr.resetDefaultApplication("image/png", (err, data) => { ...@@ -595,100 +709,11 @@ defaultAppMgr.resetDefaultApplication("image/png", (err, data) => {
}); });
``` ```
## defaultAppMgr.isDefaultApplicationSync<sup>10+</sup> ## defaultAppMgr.resetDefaultApplication
isDefaultApplicationSync(type: string): boolean;
以同步方法根据系统已定义的应用类型判断当前应用是否是该应用类型的默认应用,使用boolean形式返回结果。
**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------| ------ | ---- | --------------------------------------- |
| type | string | 是 | 要查询的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值。 |
**返回值:**
| 类型 | 说明 |
| ------- | -------------------- |
| boolean | Promise形式返回当前应用是否是默认应用,true表示是默认应用,false表示不是默认应用。 |
**示例:**
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.isDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER)
.then((data) => {
console.info('Operation successful. IsDefaultApplicationSync ? ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
```
## defaultAppMgr.getDefaultApplicationSync<sup>10+</sup>
getDefaultApplicationSync(type: string, userId?: number): BundleInfo;
以同步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型获取默认应用信息,使用BundleInfo返回结果。
**需要权限:** ohos.permission.GET_DEFAULT_APPLICATION
**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
**系统API:** 此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------| ------ | ---- | --------------------------------------- |
| type | string | 是 | 要查询的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值,或者符合媒体类型格式的文件类型。|
| userId | number | 否 | 用户ID。默认值:调用方所在用户。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------ | -------------------- |
| [BundleInfo](js-apis-bundle-BundleInfo.md) | 返回的默认应用包信息。|
**错误码:**
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
| 错误码ID | 错误信息 |
| -------- | ----------------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700023 | The specified default app does not exist. |
| 17700025 | The specified type is invalid. |
**示例:**
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.getDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER)
.then((data) => {
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
defaultAppMgr.getDefaultApplicationSync("image/png")
.then((data) => {
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
```
## defaultAppMgr.setDefaultApplicationSync<sup>10+</sup>
setDefaultApplicationSync(type: string, elementName: ElementName, userId?: number): void; resetDefaultApplication(type: string, callback: AsyncCallback\<void>) : void;
同步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型设置默认应用,返回undefined 异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型重置默认应用,使用callback形式返回结果
**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION **需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
...@@ -700,59 +725,35 @@ setDefaultApplicationSync(type: string, elementName: ElementName, userId?: numbe ...@@ -700,59 +725,35 @@ setDefaultApplicationSync(type: string, elementName: ElementName, userId?: numbe
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | --------------------------------------- | | ----------- | ------ | ---- | --------------------------------------- |
| type | string | 是 | 要设置的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值,或者符合媒体类型格式的文件类型。| | type | string | 是 | 要重置的应用类型,取[ApplicationType](#defaultappmgrapplicationtype)中的值,或者符合媒体类型格式的文件类型。 |
| elementName | [ElementName](js-apis-bundle-ElementName.md) | 是 | 要设置为默认应用的组件信息。 | | callback | AsyncCallback\<void> | 是 | 程序启动作为入参的回调函数。 |
| userId | number | 否 | 用户ID。默认值:调用方所在用户。 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------------------- |
| void | undefined对象,无返回结果的undefined对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md) 以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
| 错误码ID | 错误信息 | | 错误码ID | 错误信息 |
| -------- | ---------------------------------------------- | | -------- | ----------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700025 | The specified type is invalid. | | 17700025 | The specified type is invalid. |
| 17700028 | The specified ability does not match the type. |
**示例:** **示例:**
```ts ```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager'; import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.setDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, { defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err, data) => {
bundleName: "com.example.myapplication", if (err) {
moduleName: "module01", console.error('Operation failed. Cause: ' + JSON.stringify(err));
abilityName: "EntryAbility" return;
}).then((data) => { }
console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
let userId = 100;
defaultAppMgr.setDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, {
bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
}, userId).then((data) => {
console.info('Operation successful.'); console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
}); });
defaultAppMgr.setDefaultApplicationSync("image/png", { defaultAppMgr.resetDefaultApplication("image/png", (err, data) => {
bundleName: "com.example.myapplication", if (err) {
moduleName: "module01", console.error('Operation failed. Cause: ' + JSON.stringify(err));
abilityName: "EntryAbility" return;
}, userId).then((data) => { }
console.info('Operation successful.'); console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
}); });
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册