未验证 提交 cdfc8c46 编写于 作者: 耿文广 提交者: Gitee

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

Signed-off-by: N耿文广 <gengwenguang@huawei.com>
上级 35f40311
......@@ -63,11 +63,13 @@ isDefaultApplication(type: string): Promise\<boolean>
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
import { BusinessError } from '@ohos.base';
defaultAppMgr.isDefaultApplication(defaultAppMgr.ApplicationType.BROWSER)
.then((data: defaultAppMgr.AsyncCallback<boolean>) => {
.then((data) => {
console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
}).catch((error: BusinessError) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
```
......@@ -92,13 +94,13 @@ isDefaultApplication(type: string, callback: AsyncCallback\<boolean>): void
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
import { BusinessError } from '@ohos.base';
defaultAppMgr.isDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err: BusinessError, data: defaultAppMgr.AsyncCallback<boolean>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data));
});
defaultAppMgr.isDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data));
});
```
## defaultAppMgr.isDefaultApplicationSync<sup>10+</sup>
......@@ -126,12 +128,12 @@ isDefaultApplicationSync(type: string): boolean;
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.isDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER)
.then((data: defaultAppMgr.AsyncCallback<boolean>) => {
console.info('Operation successful. IsDefaultApplicationSync ? ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
try {
let data = defaultAppMgr.isDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER)
console.info('Operation successful. IsDefaultApplicationSync ? ' + JSON.stringify(data));
} catch(error) {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
};
```
## defaultAppMgr.getDefaultApplication
......@@ -173,21 +175,23 @@ getDefaultApplication(type: string, userId?: number): Promise\<BundleInfo>
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
import { BusinessError } from '@ohos.base';
defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER)
.then((data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
.then((data) => {
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
})
.catch((error) => {
})
.catch((error: BusinessError) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
});
defaultAppMgr.getDefaultApplication("image/png")
.then((data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
.then((data) => {
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
})
.catch((error) => {
})
.catch((error: BusinessError) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
});
```
## defaultAppMgr.getDefaultApplication
......@@ -227,20 +231,20 @@ import defaultAppMgr from '@ohos.bundle.defaultAppManager';
import { BusinessError } from '@ohos.base';
let userId = 100;
defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId, (err: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
});
defaultAppMgr.getDefaultApplication("image/png", userId, (err: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
defaultAppMgr.getDefaultApplication("image/png", userId, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
});
```
......@@ -278,19 +282,19 @@ getDefaultApplication(type: string, callback: AsyncCallback\<BundleInfo>) : void
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
import { BusinessError } from '@ohos.base';
defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
});
defaultAppMgr.getDefaultApplication("image/png", (err: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
defaultAppMgr.getDefaultApplication("image/png", (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
});
```
......@@ -333,21 +337,19 @@ getDefaultApplicationSync(type: string, userId?: number): BundleInfo;
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.getDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER)
.then((data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
defaultAppMgr.getDefaultApplicationSync("image/png")
.then((data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
try {
let data = defaultAppMgr.getDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER)
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
} catch(error) {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
};
try {
let data = defaultAppMgr.getDefaultApplicationSync("image/png")
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
} catch(error) {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
};
```
## defaultAppMgr.setDefaultApplication
......@@ -390,28 +392,30 @@ setDefaultApplication(type: string, elementName: ElementName, userId?: number):
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
let info: defaultAppMgr.ElementName = {
bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
import { BusinessError } from '@ohos.base';
let info = {
bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
}
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, info).then((data: defaultAppMgr.AsyncCallback<void>) => {
console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, info).then((data) => {
console.info('Operation successful.');
}).catch((error: BusinessError) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
let userId = 100;
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, info, userId).then((data: defaultAppMgr.AsyncCallback<void>) => {
console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, info, userId).then((data) => {
console.info('Operation successful.');
}).catch((error: BusinessError) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
defaultAppMgr.setDefaultApplication("image/png", info, userId).then((data: defaultAppMgr.AsyncCallback<void>) => {
console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
defaultAppMgr.setDefaultApplication("image/png", info, userId).then((data) => {
console.info('Operation successful.');
}).catch((error: BusinessError) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
```
......@@ -453,26 +457,26 @@ import defaultAppMgr from '@ohos.bundle.defaultAppManager';
import { BusinessError } from '@ohos.base';
let userId = 100;
let info: defaultAppMgr.ElementName = {
bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
let info = {
bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
}
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, info, userId, (errerr: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, info, userId, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
defaultAppMgr.setDefaultApplication("image/png", info, userId, (errerr: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
defaultAppMgr.setDefaultApplication("image/png", info, userId, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
```
## defaultAppMgr.setDefaultApplication
......@@ -510,26 +514,26 @@ setDefaultApplication(type: string, elementName: ElementName, callback: AsyncCal
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
import { BusinessError } from '@ohos.base';
let info: defaultAppMgr.ElementName = {
bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
let info = {
bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
}
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, info, (err: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, info, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
defaultAppMgr.setDefaultApplication("image/png", info, (err: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
defaultAppMgr.setDefaultApplication("image/png", info, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
```
## defaultAppMgr.setDefaultApplicationSync<sup>10+</sup>
......@@ -566,29 +570,32 @@ setDefaultApplicationSync(type: string, elementName: ElementName, userId?: numbe
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
let info: defaultAppMgr.ElementName = {
bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
let info = {
bundleName: "com.example.myapplication",
moduleName: "module01",
abilityName: "EntryAbility"
}
defaultAppMgr.setDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, info).then((data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
try {
defaultAppMgr.setDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, info);
console.info('Operation successful.');
} catch(error) {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
};
let userId = 100;
defaultAppMgr.setDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, info, userId).then((data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
defaultAppMgr.setDefaultApplicationSync("image/png", info, userId).then((data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
try {
defaultAppMgr.setDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, info, userId);
console.info('Operation successful.');
} catch(error) {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
};
try {
defaultAppMgr.setDefaultApplicationSync("image/png", info, userId);
console.info('Operation successful.');
} catch(error) {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
};
```
## defaultAppMgr.resetDefaultApplication
......@@ -623,22 +630,24 @@ resetDefaultApplication(type: string, userId?: number): Promise\<void>
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
import { BusinessError } from '@ohos.base';
let userId = 100;
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId)
.then((data: defaultAppMgr.AsyncCallback<void>) => {
.then((data) => {
console.info('Operation successful.');
})
.catch((error) => {
})
.catch((error: BusinessError) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
});
defaultAppMgr.resetDefaultApplication("image/png", userId)
.then((data: defaultAppMgr.AsyncCallback<void>) => {
.then((data) => {
console.info('Operation successful.');
})
.catch((error) => {
})
.catch((error: BusinessError) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
});
```
## defaultAppMgr.resetDefaultApplication
......@@ -677,20 +686,20 @@ import defaultAppMgr from '@ohos.bundle.defaultAppManager';
import { BusinessError } from '@ohos.base';
let userId = 100;
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId, (err: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
defaultAppMgr.resetDefaultApplication("image/png", userId, (err: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
defaultAppMgr.resetDefaultApplication("image/png", userId, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
```
......@@ -727,20 +736,20 @@ resetDefaultApplication(type: string, callback: AsyncCallback\<void>) : void;
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
import { BusinessError } from '@ohos.base';
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
defaultAppMgr.resetDefaultApplication("image/png", (err: BusinessError, data: defaultAppMgr.AsyncCallback<BundleInfo>) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
defaultAppMgr.resetDefaultApplication("image/png", (err: BusinessError, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful.');
});
```
......@@ -776,20 +785,19 @@ resetDefaultApplicationSync(type: string, userId?: number): void;
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
let userId = 100;
defaultAppMgr.resetDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, userId)
.then((data: defaultAppMgr.AsyncCallback<void>) => {
console.info('Operation successful.');
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
defaultAppMgr.resetDefaultApplicationSync("image/png", userId)
.then((data: defaultAppMgr.AsyncCallback<void>) => {
console.info('Operation successful.');
})
.catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
let userId = 100;
try {
defaultAppMgr.resetDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, userId);
console.info('Operation successful.');
} catch(error) {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
};
try {
defaultAppMgr.resetDefaultApplicationSync("image/png", userId);
console.info('Operation successful.');
} catch(error) {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
};
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册