提交 9a8fb2df 编写于 作者: W wusongqing

updated docs

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 3bf254eb
# APIs
- Ability Framework
- [FeatureAbility Module](js-apis-featureAbility.md)
- [ParticleAbility Module](js-apis-particleAbility.md)
- [DataUriUtils Module](js-apis-DataUriUtils.md)
- [Context Module](js-apis-Context.md)
- Event Notification
- [CommonEvent Module](js-apis-commonEvent.md)
- [Notification Module](js-apis-notification.md)
- Resource Management
- [Resource Manager](js-apis-resource-manager.md)
- [Internationalization \(intl\) ](js-apis-intl.md)
......@@ -47,6 +55,7 @@
- [Animation](js-apis-basic-features-animator.md)
- [HiAppEvent](js-apis-hiappevent.md)
- [Performance Tracing](js-apis-bytrace.md)
- [Fault Logger](js-apis-faultLogger.md)
- Language Base Class Library
- [Obtaining Process Information](js-apis-process.md)
- [URL String Parsing](js-apis-url.md)
......
# Context Module
## Applicable Devices
| API | Phone| Tablet| Smart TV| Wearable| Lite Wearable| SmartVision Device|
| ------------------------------------------------------------ | ---- | ---- | ------ | -------- | -------------- | ------------ |
| Context.getOrCreateLocalDir(callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| Context.getOrCreateLocalDir() | Yes| Yes| Yes| Yes| No| No|
| Context.verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\<number>) | Yes| Yes| Yes| Yes| No| No|
| Context.verifyPermission(permission: string, callback: AsyncCallback\<number>) | Yes| Yes| Yes| Yes| No| No|
| Context.verifyPermission(permission: string, options?: PermissionOptions) | Yes| Yes| Yes| Yes| No| No|
| Context.requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, resultCallback: AsyncCallback\<PermissionRequestResult>) | Yes| Yes| Yes| Yes| No| No|
| Context.getApplicationInfo(callback: AsyncCallback\<ApplicationInfo>) | Yes| Yes| Yes| Yes| No| No|
| Context.getApplicationInfo() | Yes| Yes| Yes| Yes| No| No|
| Context.getBundleName(callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| Context.getBundleName() | Yes| Yes| Yes| Yes| No| No|
| Context.getProcessInfo(callback: AsyncCallback\<ProcessInfo>) | Yes| Yes| Yes| Yes| No| No|
| Context.getProcessInfo() | Yes| Yes| Yes| Yes| No| No|
| Context.getElementName(callback: AsyncCallback\<ElementName>) | Yes| Yes| Yes| Yes| No| No|
| Context.getElementName() | Yes| Yes| Yes| Yes| No| No|
| Context.getProcessName(callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| Context.getProcessName() | Yes| Yes| Yes| Yes| No| No|
| Context.getCallingBundle(callback: AsyncCallback\<string>) | Yes| Yes| Yes| Yes| No| No|
| Context.getCallingBundle() | Yes| Yes| Yes| Yes| No| No|
## Modules to Import
```js
import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle'
```
The **Context** object is created in a **featureAbility** and returned through its **getContext()** method. Therefore, you must import the **@ohos.ability.featureAbility** package before using the Context module. An example is as follows:
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getOrCreateLocalDir()
```
## Context.getOrCreateLocalDir(callback: AsyncCallback<string>)
- Functionality
Obtains the local root directory of the application. If this method is called for the first time, a root directory is created. This method uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | ---------------------- | ---- | ------------------------ |
| callback | Read-only| AsyncCallback\<string> | Yes| Callback used to return the local root directory of the application.|
- Return values
void
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getOrCreateLocalDir((err, data)=>{
console.info("data=" + data);
})
```
## Context.getOrCreateLocalDir()
- Functionality
Obtains the local root directory of the application. If this method is called for the first time, a root directory is created. This method uses a promise to return the result.
- Parameters
None
- Return values
| Type| Description|
| --------------- | -------------------- |
| Promise<string> | Promise used to return the local root directory of the application.|
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getOrCreateLocalDir().then((void) => {
console.info("==========================>getOrCreateLocalDirCallback=======================>");
});
```
## PermissionOptions
| Name| Readable/Writable| Type| Mandatory| Description|
| ---- | -------- | ------ | ---- | ------ |
| pid | Read-only| number | No| PID.|
| uid | Read-only| number | No| UID.|
## Context.verifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback<number>)
- Functionality
Verifies whether a specific PID and UID have the given permission. This method uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| ---------- | -------- | ----------------------------------------------- | ---- | ----------------------------------- |
| permission | Read-only| string | Yes| Name of the permission to verify.|
| options | Read-only| [PermissionOptions](#PermissionOptions)| Yes| Permission options.|
| callback | Read-only| AsyncCallback\<number> | Yes| Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
- Return values
void
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle'
var context = featureAbility.getContext();
var datainfo = await bundle.getBundleInfo('com.context.test',1);
context.verifyPermission("com.example.permission",datainfo.uid)
```
## Context.verifyPermission(permission: string, callback: AsyncCallback<number>)
- Functionality
Verifies whether the current PID and UID have the given permission. This method uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| ---------- | -------- | ---------------------- | ---- | ----------------------------------- |
| permission | Read-only| string | Yes| Name of the permission to verify.|
| callback | Read-only| AsyncCallback\<number> | Yes| Callback used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
- Return values
void
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.verifyPermission("com.example.permission")
```
## Context.verifyPermission(permission: string, options?: PermissionOptions)
- Functionality
Verifies whether a specific PID and UID have the given permission. This method uses a promise to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| ---------- | -------- | ----------------------------------------------- | ---- | -------------- |
| permission | Read-only| string | Yes| Name of the permission to verify.|
| options | Read-only| [PermissionOptions](#PermissionOptions)| No| Permission options.|
- Return values
| Type| Description|
| --------------- | ------------------------------------------------------------ |
| Promise<number> | Promise used to return the permission verification result. The value **0** indicates that the PID and UID have the given permission, and the value **-1** indicates that the PID and UID do not have the given permission.|
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
var Permission = context.PermissionOptions(1,1);
context.getOrCreateLocalDir('com.context.permission',Permission).then((void) => {
console.info("==========================>verifyPermissionCallback=======================>");
});
```
## PermissionRequestResult
| Name| Readable/Writable| Type| Mandatory| Description|
| ----------- | -------- | -------------- | ---- | ------------------ |
| requestCode | Read-only| number | Yes| Request code passed.|
| permissions | Read-only| Array\<string> | Yes| Permissions passed.|
| authResults | Read-only| Array\<number> | Yes| Permission request result.|
## Context.requestPermissionsFromUser(permissions: Array<string>, requestCode: number, resultCallback: AsyncCallback<[PermissionRequestResult](#PermissionRequestResult)>)
- Functionality
Requests certain permissions from the system. This method uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| -------------- | -------- | ------------------------------------------------------------ | ---- | --------------------------------------------- |
| permissions | Read-only| Array\<string> | Yes| Permissions to request. This parameter cannot be **null**.|
| requestCode | Read-only| number | Yes| Request code to be passed to **PermissionRequestResult**.|
| resultCallback | Read-only| AsyncCallback\<[PermissionRequestResult](#PermissionRequestResult)> | Yes| Permission request result.|
- Return values
void
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getOrCreateLocalDir(
["com.example.permission1",
"com.example.permission2",
"com.example.permission3",
"com.example.permission4",
"com.example.permission5"],
1,
)
```
## Context.getApplicationInfo(callback: AsyncCallback<ApplicationInfo>)
- Functionality
Obtains information about the current application. This method uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | ------------------------------- | ---- | ---------------------- |
| callback | Read-only| AsyncCallback\<ApplicationInfo> | Yes| Callback used to return the application information.|
- Return values
void
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getApplicationInfo()
```
## Context.getApplicationInfo
- Functionality
Obtains information about the current application. This method uses a promise to return the result.
- Parameters
None
- Return values
| Type| Description|
| ------------------------ | ------------------ |
| Promise<ApplicationInfo> | Promise used to return the application information.|
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getApplicationInfo().then((void) => {
console.info("==========================>getApplicationInfoCallback=======================>");
});
```
## Context.getBundleName(callback: AsyncCallback<string>)
- Functionality
Obtains the bundle name of the current ability. This method uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | ---------------------- | ---- | --------------------------- |
| callback | Read-only| AsyncCallback\<string> | Yes| Callback used to return the bundle name.|
- Return values
void
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getBundleName()
```
## Context.getBundleName
- Functionality
Obtains the bundle name of the current ability. This method uses a promise to return the result.
- Parameters
None
- Return values
| Type| Description|
| --------------- | ----------------------- |
| Promise<string> | Promise used to return the bundle name.|
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getBundleName().then((void) => {
console.info("==========================>getBundleNameCallback=======================>");
});
```
## Context.getProcessInfo(callback: AsyncCallback<ProcessInfo>)
- Functionality
Obtains information about the current process, including the PID and process name. This method uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | --------------------------- | ---- | ------------------ |
| callback | Read-only| AsyncCallback\<ProcessInfo> | Yes| Callback used to return the process information.|
- Return values
void
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getProcessInfo()
```
## Context.getProcessInfo
- Functionality
Obtains information about the current process, including the PID and process name. This method uses a promise to return the result.
- Parameters
None
- Return values
| Type| Description|
| -------------------- | -------------- |
| Promise<ProcessInfo> | Promise used to return the process information.|
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getProcessInfo().then((void) => {
console.info("==========================>getProcessInfoCallback=======================>");
});
```
## Context.getElementName(callback: AsyncCallback<ElementName>)
- Functionality
Obtains the **ohos.bundle.ElementName** object of the current ability. This method is available only to Page abilities. It uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | --------------------------- | ---- | -------------------------------------------- |
| callback | Read-only| AsyncCallback\<ElementName> | Yes| Callback used to return the **ohos.bundle.ElementName** object.|
- Return values
void
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getElementName()
```
## Context.getElementName
- Functionality
Obtains the **ohos.bundle.ElementName** object of the current ability. This method is available only to Page abilities. It uses a promise to return the result.
- Parameters
None
- Return values
| Type| Description|
| -------------------- | ---------------------------------------- |
| Promise<ElementName> | Promise used to return the **ohos.bundle.ElementName** object.|
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getElementName().then((void) => {
console.info("==========================>getElementNameCallback=======================>");
});
```
## **Context.getProcessName(callback: AsyncCallback<string>)**
- Functionality
Obtains the name of the current process. This method uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | ---------------------- | ---- | ------------------ |
| callback | Read-only| AsyncCallback\<string> | Yes| Callback used to return the process name.|
- Return values
void
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getProcessName()
```
## Context.getProcessName
- Functionality
Obtains the name of the current process. This method uses a promise to return the result.
- Parameters
None
- Return values
| Type| Description|
| --------------- | -------------- |
| Promise<string> | Promise used to return the process name.|
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getProcessName().then((void) => {
console.info("==========================>getProcessNameCallback=======================>");
});
```
## Context.getCallingBundle(callback: AsyncCallback<string>)
- Functionality
Obtains the bundle name of the calling ability. This method uses a callback to return the result.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| -------- | -------- | ---------------------- | ---- | ------------------------- |
| callback | Read-only| AsyncCallback\<string> | Yes| Callback used to return the bundle name.|
- Return values
void
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getCallingBundle()
```
## Context.getCallingBundle
- Functionality
Obtains the bundle name of the calling ability. This method uses a promise to return the result.
- Parameters
None
- Return values
| Type| Description|
| --------------- | ------------------------- |
| Promise<string> | Promise used to return the bundle name.|
- Example
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getCallingBundle().then((void) => {
console.info("==========================>getCallingBundleCallback=======================>");
});
```
# DataUriUtils Module
## Modules to Import
```js
import dataUriUtils from '@ohos.ability.dataUriUtils';
```
## DataUriUtils.getId
- Functionality
Obtains the ID attached to the end of a given URI.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| ---- | -------- | ------ | ---- | ------------------------- |
| uri | Read-only| string | Yes| URI object from which the ID is to be obtained.|
- Return values
Returns the ID obtained from the URI object.
- Example
```js
import dataUriUtils from '@ohos.ability.datauriutils'
dataUriUtils.getIdSync("com.example.dataUriUtils/1221")
```
## DataUriUtils.attachId
- Functionality
Attaches an ID to the end of a given URI.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| ---- | -------- | ------ | ---- | ------------------------- |
| uri | Read-only| string | Yes| URI object to which an ID is to be attached.|
| id | Read-only| number | Yes| ID to be attached.|
- Return values
Returns the URI object with the ID attached.
- Example
```js
import dataUriUtils from '@ohos.ability.datauriutils'
var idint = 1122;
dataUriUtils.attachId(
"com.example.dataUriUtils"
idint,
)
```
## DataUriUtils.deleteId
- Functionality
Deletes the ID from the end of a given URI.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| ---- | -------- | ------ | ---- | ------------------------- |
| uri | Read-only| string | Yes| URI object from which the ID is to be deleted.|
- Return values
Returns the URI object with the ID deleted.
- Example
```js
import dataUriUtils from '@ohos.ability.datauriutils'
dataUriUtils.deleteId("com.example.dataUriUtils/1221")
```
## DataUriUtils.updateId
- Functionality
Updates the ID in a given URI.
- Parameters
| Name| Readable/Writable| Type| Mandatory| Description|
| ---- | -------- | ------ | ---- | ------------------- |
| uri | Read-only| string | Yes| URI object to be updated.|
| id | Read-only| number | Yes| New ID.|
- Return values
Returns the URI object with the new ID.
- Example
```js
import dataUriUtils from '@ohos.ability.datauriutils'
var idint = 1122;
dataUriUtils.updateId(
"com.example.dataUriUtils"
idint,
)
```
......@@ -696,19 +696,19 @@ this.StartContinueAbility(remoteDeviceId); //remoteDeviceId is acquired from Dev
| Name| Name| Description|
| ------------------------------------ | ---------- | ------------------------------------------------------------ |
| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Permission to read the URI.|
| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Permission to write the URI.|
| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Whether to return the result to the ability.|
| FLAG_ABILITY_CONTINUATION | 0x00000008 | Whether abilities on the local device can be migrated to a remote device.|
| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Whether a component belongs to OHOS.|
| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Whether to enable an ability.|
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Permission to make the URI persist.|
| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Permission to authenticate prefix URI.|
| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Support for the startup across multiple devices in a distributed scheduler.|
| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Functionality of using the Service template is enabled regardless of whether the host application is started.|
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Whether the migration is reversible.|
| FLAG_INSTALL_ON_DEMAND | 0x00000800 | A demand for the installation of a specific function.|
| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | A demand for the installation of a specific function in background mode.|
| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | An instruction for clearing other tasks. This flag can be set for the **Want** object passed to **ohos.app.Context#startAbility** and must be used together with **flag_ABILITY_NEW_MISSION**.|
| FLAG_ABILITY_NEW_MISSION | 0x10000000 | An instruction for creating a task on the history task stack.|
| FLAG_ABILITY_MISSION_TOP | 0x20000000 | An existing instance of the ability to start will be reused if it is already at the top of the task stack. Otherwise, a new ability instance is created.|
| FLAG_AUTH_READ_URI_PERMISSION | 0x00000001 | Indicates the permission to read the URI.|
| FLAG_AUTH_WRITE_URI_PERMISSION | 0x00000002 | Indicates the permission to write the URI.|
| FLAG_ABILITY_FORWARD_RESULT | 0x00000004 | Returns the result to the ability.|
| FLAG_ABILITY_CONTINUATION | 0x00000008 | Indicates whether the ability on the local device can be migrated to a remote device.|
| FLAG_NOT_OHOS_COMPONENT | 0x00000010 | Indicates that a component does not belong to OHOS.|
| FLAG_ABILITY_FORM_ENABLED | 0x00000020 | Indicates whether to enable an ability.|
| FLAG_AUTH_PERSISTABLE_URI_PERMISSION | 0x00000040 | Indicates the permission to make the URI persistent.|
| FLAG_AUTH_PREFIX_URI_PERMISSION | 0x00000080 | Indicates the permission to verify URIs by prefix matching.|
| FLAG_ABILITYSLICE_MULTI_DEVICE | 0x00000100 | Supports cross-device startup in a distributed scheduler.|
| FLAG_START_FOREGROUND_ABILITY | 0x00000200 | Indicates that the Service ability is started regardless of whether the host application has been started.|
| FLAG_ABILITY_CONTINUATION_REVERSIBLE | 0x00000400 | Indicates that the migration is reversible.|
| FLAG_INSTALL_ON_DEMAND | 0x00000800 | Indicates that the specific ability will be installed if it has not been installed.|
| FLAG_INSTALL_WITH_BACKGROUND_MODE | 0x80000000 | Indicates that the specific ability will be installed in the background if it has not been installed.|
| FLAG_ABILITY_CLEAR_MISSION | 0x00008000 | Clears other operation missions. This flag can be set for the **Want** object passed to **ohos.app.Context#startAbility** and must be used together with **flag_ABILITY_NEW_MISSION**.|
| FLAG_ABILITY_NEW_MISSION | 0x10000000 | Creates a mission on the historical mission stack.|
| FLAG_ABILITY_MISSION_TOP | 0x20000000 | Starts the mission on the top of the existing mission stack; creates an ability instance if no mission exists.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册