提交 f155c062 编写于 作者: zyjhandsome's avatar zyjhandsome

Merge branch 'master' of https://gitee.com/openharmony/docs

......@@ -192,7 +192,7 @@ zh-cn/application-dev/napi/rawfile_guidelines.md @ningningW
zh-cn/application-dev/background-agent-scheduled-reminder/ @RayShih
zh-cn/application-dev/background-task-management/ @ningningW @wangwenli_wolf @tangtiantian2021 @nan-xiansen
zh-cn/application-dev/work-scheduler/ @ningningW
zh-cn/application-dev/internationalization/ @ningningW @Buda-Liu @budda-wang @yangqing3
zh-cn/application-dev/internationalization/ @ningningW @Buda-Liu @mengjingzhimo @yangqing3
zh-cn/application-dev/device/usb-overview.md @ge-yafang @jasonyujia @andeszhang @liuhonggang123
zh-cn/application-dev/device/usb-guidelines.md @ge-yafang @jasonyujia @andeszhang @liuhonggang123
zh-cn/application-dev/device/device-location-overview.md @RayShih
......
......@@ -10,17 +10,18 @@ The geographic description helps users understand a location easily by providing
## Available APIs
The following table describes APIs available for mutual conversion between coordinates and geographic description. For details, see [Geolocation Manager](../reference/apis/js-apis-geoLocationManager.md).
The following table describes APIs available for mutual conversion between coordinates and geographic description. For details, see [Geolocation Manager](../reference/apis/js-apis-geolocation.md).
**Table1** APIs for geocoding and reverse geocoding
| API | Description |
| -------- | -------- |
| isGeocoderAvailable(): boolean; | Obtains the (reverse) geocoding service status.|
| getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void | Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result. |
| getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise<Array<GeoAddress>> | Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result. |
| getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void | Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result. |
| getAddressesFromLocationName(request: GeoCodeRequest): Promise<Array<GeoAddress>> | Converts geographic description into coordinates through geocoding. This API uses a promise to return the result. |
| isGeoServiceAvailable(callback: AsyncCallback<boolean>) : void | Checks whether the (reverse) geocoding service is available. This API uses an asynchronous callback to return the result.|
| isGeoServiceAvailable() : Promise<boolean> | Checks whether the (reverse) geocoding service is available. This API uses a promise to return the result.|
| getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>) : void | Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result. |
| getAddressesFromLocation(request: ReverseGeoCodeRequest) : Promise<Array<GeoAddress>> | Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result. |
| getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>) : void | Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result. |
| getAddressesFromLocationName(request: GeoCodeRequest) : Promise<Array<GeoAddress>> | Converts geographic description into coordinates through geocoding. This API uses a promise to return the result. |
## How to Develop
......@@ -29,21 +30,22 @@ The following table describes APIs available for mutual conversion between coord
>
> The **GeoConvert** instance needs to access backend services to obtain information. Therefore, before performing the following steps, ensure that your device is connected to the network.
1. Import the **geoLocationManager** module by which you can implement all APIs related to the geocoding and reverse geocoding conversion capabilities.
1. Import the **geolocation** module by which you can implement all APIs related to the geocoding and reverse geocoding conversion capabilities.
```ts
import geoLocationManager from '@ohos.geoLocationManager';
import geolocation from '@ohos.geolocation';
```
2. Query whether geocoder service is available.
- Call **isGeoServiceAvailable** to query whether the geocoder service is available. If the service is available, continue with step 3.
```ts
import geoLocationManager from '@ohos.geoLocationManager';
try {
var isAvailable = geoLocationManager.isGeocoderAvailable();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
geolocation.isGeoServiceAvailable((err, data) => {
if (err) {
console.log('isGeoServiceAvailable err: ' + JSON.stringify(err));
} else {
console.log('isGeoServiceAvailable data: ' + JSON.stringify(data));
}
});
```
3. Obtain the conversion result.
......@@ -51,7 +53,7 @@ The following table describes APIs available for mutual conversion between coord
```ts
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) {
console.log('getAddressesFromLocation err: ' + JSON.stringify(err));
} else {
......@@ -60,12 +62,12 @@ The following table describes APIs available for mutual conversion between coord
});
```
Your application can obtain the **GeoAddress** list that matches the specified coordinates and then read location information from it. For details, see [Geolocation](../reference/apis/js-apis-geoLocationManager.md).
Your application can obtain the **GeoAddress** list that matches the specified coordinates and then read location information from it. For details, see [Geolocation](../reference/apis/js-apis-geolocation.md).
- Call **getAddressesFromLocationName** to convert geographic description into coordinates.
```ts
var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => {
geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => {
if (err) {
console.log('getAddressesFromLocationName err: ' + JSON.stringify(err));
} else {
......@@ -74,6 +76,6 @@ The following table describes APIs available for mutual conversion between coord
});
```
Your application can obtain the **GeoAddress** list that matches the specified location information and read coordinates from it. For details, see [Geolocation](../reference/apis/js-apis-geoLocationManager.md).
Your application can obtain the **GeoAddress** list that matches the specified location information and read coordinates from it. For details, see [Geolocation](../reference/apis/js-apis-geolocation.md).
To improve the accuracy of location results, you can set the longitude and latitude ranges in **GeoCodeRequest**.
......@@ -10,11 +10,11 @@ Real-time location of the device is recommended for location-sensitive services.
## Available APIs
For details about the APIs used to obtain the device location information, see [Geolocation Manager](../reference/apis/js-apis-geoLocationManager.md).
For details about the APIs used to obtain the device location information, see [Geolocation Manager](../reference/apis/js-apis-geolocation.md).
## How to Develop
To learn more about the APIs for obtaining device location information, see [Geolocation](../reference/apis/js-apis-geoLocationManager.md).
To learn more about the APIs for obtaining device location information, see [Geolocation](../reference/apis/js-apis-geolocation.md).
1. Before using basic location capabilities, check whether your application has been granted the permission to access the device location information. If not, your application needs to obtain the permission from the user as described below.
The system provides the following location permissions:
......@@ -41,10 +41,10 @@ To learn more about the APIs for obtaining device location information, see [Geo
You can declare the required permission in your application's configuration file. For details, see [Access Control (Permission) Development](../security/accesstoken-guidelines.md).
2. Import the **geoLocationManager** module by which you can implement all APIs related to the basic location capabilities.
2. Import the **geolocation** module by which you can implement all APIs related to the basic location capabilities.
```ts
import geoLocationManager from '@ohos.geoLocationManager';
```
import geolocation from '@ohos.geolocation';
```
3. Instantiate the **LocationRequest** object. This object provides APIs to notify the system of the location service type and the interval of reporting location information.<br>
......@@ -53,7 +53,7 @@ To learn more about the APIs for obtaining device location information, see [Geo
To better serve your needs for using APIs, the system has categorized APIs into different packages to match your common use cases of the location function. In this way, you can directly use the APIs specific to a certain use case, making application development much easier. The following table lists the use cases currently supported.
```ts
```
export enum LocationRequestScenario {
UNSET = 0x300,
NAVIGATION,
......@@ -78,7 +78,7 @@ To learn more about the APIs for obtaining device location information, see [Geo
Sample code for initializing **requestInfo** for navigation:
```ts
var requestInfo = {'scenario': geoLocationManager.LocationRequestScenario.NAVIGATION, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var requestInfo = {'scenario': geolocation.LocationRequestScenario.NAVIGATION, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
```
**Method 2:**
......@@ -107,7 +107,7 @@ To learn more about the APIs for obtaining device location information, see [Geo
Sample code for initializing **requestInfo** for the location accuracy priority policy:
```ts
var requestInfo = {'priority': geoLocationManager.LocationRequestPriority.ACCURACY, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var requestInfo = {'priority': geolocation.LocationRequestPriority.ACCURACY, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
```
4. Instantiate the **Callback** object for the system to report location results.
......@@ -122,24 +122,25 @@ To learn more about the APIs for obtaining device location information, see [Geo
5. Start device location.
```ts
geoLocationManager.on('locationChange', requestInfo, locationChange);
geolocation.on('locationChange', requestInfo, locationChange);
```
6. (Optional) Stop device location.
```ts
geoLocationManager.off('locationChange', locationChange);
geolocation.off('locationChange', locationChange);
```
If your application does not need the real-time device location, it can use the last known device location cached in the system instead.
```ts
import geoLocationManager from '@ohos.geoLocationManager';
try {
var location = geoLocationManager.getLastLocation();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
geolocation.getLastLocation((err, data) => {
if (err) {
console.log('getLastLocation: err: ' + JSON.stringify(err));
} else {
console.log('getLastLocation: data: ' + JSON.stringify(data));
}
});
```
To call this method, your application needs to request the **ohos.permission.LOCATION** permission from the user.
......@@ -385,7 +385,6 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
let permissionFlag = 1;
try {
atManager.getPermissionFlags(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS").then((data) => {
console.log(`getPermissionFlags success, data->${JSON.stringify(data)}`);
......@@ -459,11 +458,12 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
**Example**
```js
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
let tokenIDList: Array<number> = [];
let permissionNameList = [];
let appInfo = bundle.getApplicationInfoSync('com.example.myapplication', 0, 100);
let tokenIDList: Array<number> = [appInfo.accessTokenId];
let permissionNameList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"];
try {
atManager.on('permissionStateChange', tokenIDList, permissionNameList, (data) => {
console.debug("receive permission state change, data:" + JSON.stringify(data));
......@@ -508,11 +508,12 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
**Example**
```js
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
let tokenIDList: Array<number> = [];
let permissionNameList = [];
let appInfo = bundle.getApplicationInfoSync('com.example.myapplication', 0, 100);
let tokenIDList: Array<number> = [appInfo.accessTokenId];
let permissionNameList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"];
try {
atManager.off('permissionStateChange', tokenIDList, permissionNameList);
} catch(err) {
......
# Fault Logger
> **NOTE**<br/>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
......@@ -30,7 +30,7 @@ If your application needs to access the device location information, it must fir
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|
If your application needs to access the device location information when running in the background, it must be configured to be able to run in the background and be granted the **ohos.permission.LOCATION_IN_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background.
If your application needs to access the device location information when running in the background, it must be configured to be able to run in the background and be granted the **ohos.permission.LOCATION\_IN\_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background.
You can declare the required permission in your application's configuration file. For details, see [Access Control (Permission) Development](../../security/accesstoken-guidelines.md).
......@@ -1615,7 +1615,7 @@ Obtains the current country code.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Promise&lt;[CountryCode](#countrycode)&gt; | [CountryCode](#countrycode) | NA | Promise used to return the country code.|
| Promise&lt;[CountryCode](#countrycode)&gt; | [CountryCode](#countrycode) | NA | Callback used to return the country code.|
**Error codes**
......@@ -1815,7 +1815,7 @@ For details about the following error codes, see [Location Error Codes](../error
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;): void;
Sets information of the mock reverse geocoding function, including the mapping between a location and geographical name. If the location is contained in the configurations during reverse geocoding query, the corresponding geographical name will be returned.
Sets information of the mock reverse geocoding function, including the mapping between a location and geographic name. If the location is contained in the configurations during reverse geocoding query, the corresponding geographic name will be returned.
**System capability**: SystemCapability.Location.Location.Core
......@@ -1825,7 +1825,7 @@ Sets information of the mock reverse geocoding function, including the mapping b
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | Yes| Array of information of the mock reverse geocoding function, including a location and a geographical name.|
| mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | Yes| Array of information of the mock reverse geocoding function, including a location and a geographic name.|
**Error codes**
......@@ -1874,7 +1874,7 @@ Checks whether a user agrees with the privacy statement of the location service.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| boolean | boolean | NA | Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
| boolean | boolean | NA | Result indicating whether the user agrees with the privacy statement.|
**Error codes**
......@@ -1913,7 +1913,7 @@ Sets the user confirmation status for the privacy statement of the location serv
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | [LocationPrivacyType](#locationprivacytype) | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when the location service is enabled.|
| isConfirmed | boolean | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
| isConfirmed | boolean | Yes| Whether the user agrees with the privacy statement.|
**Error codes**
......@@ -1975,7 +1975,7 @@ Defines a reverse geocoding request.
| -------- | -------- | -------- | -------- | -------- |
| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| latitude | number | Yes| Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
| maxItems | number | Yes| Yes| Maximum number of location records to be returned.|
......@@ -2005,7 +2005,7 @@ Defines a geographic location.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude | number | Yes| No | Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number | Yes| No | Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| longitude | number | Yes| No | Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
| locale | string | Yes| No | Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| placeName | string | Yes| No | Landmark of the location.|
| countryCode | string | Yes| No | Country code.|
......@@ -2022,7 +2022,7 @@ Defines a geographic location.
| addressUrl | string | Yes| No| Website URL.|
| descriptions | Array&lt;string&gt; | Yes| No| Additional descriptions.|
| descriptionsSize | number | Yes| No| Total number of additional descriptions.|
| isFromMock | Boolean | Yes| No| Whether the geographical name is from the mock reverse geocoding function.|
| isFromMock | Boolean | Yes| No| Whether the geographic name is from the mock reverse geocoding function.|
## LocationRequest
......@@ -2142,7 +2142,7 @@ Defines a location.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude | number| Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number| Yes| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| longitude | number| Yes| No| Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
| altitude | number | Yes| No| Location altitude, in meters.|
| accuracy | number | Yes| No| Location accuracy, in meters.|
| speed | number | Yes| No|Speed, in m/s.|
......@@ -2165,7 +2165,7 @@ Represents information of the mock reverse geocoding function.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| location | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Yes| Latitude and longitude information.|
| geoAddress | [GeoAddress](#geoaddress) | Yes| Yes|Geographical name.|
| geoAddress | [GeoAddress](#geoaddress) | Yes| Yes|Geographic name.|
## LocationMockConfig
......
......@@ -19,9 +19,9 @@ The system provides the following location permissions:
If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking:
API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
- API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
API version 9 and later: Apply for **ohos.permission.APPROXIMATELY\_LOCATION**, or apply for **ohos.permission.APPROXIMATELY\_LOCATION** and **ohos.permission.LOCATION**. Note that **ohos.permission.LOCATION** cannot be applied for separately.
- API version 9 and later: Apply for **ohos.permission.APPROXIMATELY\_LOCATION**, or apply for **ohos.permission.APPROXIMATELY\_LOCATION** and **ohos.permission.LOCATION**. Note that **ohos.permission.LOCATION** cannot be applied for separately.
| API Version| Location Permission| Permission Application Result| Location Accuracy|
| -------- | -------- | -------- | -------- |
......@@ -30,7 +30,7 @@ API version 9 and later: Apply for **ohos.permission.APPROXIMATELY\_LOCATION**,
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|
If your application needs to access the device location information when running in the background, it must be configured to be able to run in the background and be granted the **ohos.permission.LOCATION_IN_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background.
If your application needs to access the device location information when running in the background, it must be configured to be able to run in the background and be granted the **ohos.permission.LOCATION\_IN\_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background.
You can declare the required permission in your application's configuration file. For details, see [Access Control (Permission) Development](../../security/accesstoken-guidelines.md).
......@@ -971,7 +971,7 @@ Converts geographic description into coordinates through geocoding. This API use
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Array&lt;[GeoAddress](#geoaddress)&gt;|NA|Callback used to return the geocoding result.|
| Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Array&lt;[GeoAddress](#geoaddress)&gt;|NA|Promise used to return the geocoding result.|
**Example**
......@@ -1265,7 +1265,7 @@ Defines a reverse geocoding request.
| -------- | -------- | -------- | -------- | -------- |
| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| latitude | number | Yes| Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
| maxItems | number | Yes| Yes| Maximum number of location records to be returned.|
......@@ -1305,7 +1305,7 @@ Defines a geographic location.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude<sup>7+</sup> | number | Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude<sup>7+</sup> | number | Yes| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| longitude<sup>7+</sup> | number | Yes| No| Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
| locale<sup>7+</sup> | string | Yes| No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| placeName<sup>7+</sup> | string | Yes| No| Landmark of the location.|
| countryCode<sup>7+</sup> | string | Yes| No| Country code.|
......@@ -1493,7 +1493,7 @@ Defines a location.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude<sup>7+</sup> | number | Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude<sup>7+</sup> | number | Yes| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| longitude<sup>7+</sup> | number | Yes| No| Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
| altitude<sup>7+</sup> | number | Yes| No| Location altitude, in meters.|
| accuracy<sup>7+</sup> | number | Yes| No| Location accuracy, in meters.|
| speed<sup>7+</sup> | number | Yes| No| Speed, in m/s.|
......
# HiAppEvent
This module provides the application event logging functions, such as writing application events to the event file and managing the event logging configuration.
The HiAppEvent module provides the application event logging functions, such as writing application events to the event file and managing the event logging configuration.
> **NOTE**
> - The APIs provided by this module are deprecated since API version 9. You are advised to use [`@ohos.hiviewdfx.hiAppEvent`](js-apis-hiviewdfx-hiappevent.md) instead.
......
# HiDebug
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
This module provides APIs for you to obtain the memory usage of an application, including the static heap memory (native heap) and proportional set size (PSS) occupied by the application process. You can also export VM memory slices and collect VM CPU profiling data.
The HiDebug module provides APIs for you to obtain the memory usage of an application, including the static heap memory (native heap) and proportional set size (PSS) occupied by the application process. You can also export VM memory slices and collect VM CPU profiling data.
## Modules to Import
......@@ -24,7 +25,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release.
**Return value**
| Type | Description |
| Type | Description |
| ------ | --------------------------- |
| bigint | Total heap memory size of the application, in KB.|
......
......@@ -45,7 +45,7 @@ Enumerates the log levels.
**System capability**: SystemCapability.HiviewDFX.HiLog
| Name | Default Value| Description |
| Name | Value| Description |
| ----- | ------ | ------------------------------------------------------------ |
| DEBUG | 3 | Log level used to record more detailed process information than INFO logs to help developers analyze service processes and locate faults.|
| INFO | 4 | Log level used to record key service process nodes and exceptions that occur during service running,<br>for example, no network signal or login failure.<br>These logs should be recorded by the dominant module in the service to avoid repeated logging conducted by multiple invoked modules or low-level functions.|
......
......@@ -18,9 +18,9 @@ import http from '@ohos.net.http';
```js
import http from '@ohos.net.http';
// Each HttpRequest corresponds to an HttpRequestTask object and cannot be reused.
// Each httpRequest corresponds to an HTTP request task and cannot be reused.
let httpRequest = http.createHttp();
// Subscribe to the HTTP response header, which is returned earlier than httpRequest. Whether to subscribe to the HTTP response header is up to your decision.
// This API is used to listen for the HTTP Response Header event, which is returned earlier than the result of the HTTP request. It is up to you whether to listen for HTTP Response Header events.
// on('headerReceive', AsyncCallback) is replaced by on('headersReceive', Callback) since API version 8.
httpRequest.on('headersReceive', (header) => {
console.info('header: ' + JSON.stringify(header));
......@@ -38,14 +38,18 @@ httpRequest.request(
extraData: {
"data": "data to send",
},
connectTimeout: 60000, // Optional. The default value is 60000, in ms.
expectDataType: http.HttpDataType.STRING, // Optional. This field specifies the type of the return data.
usingCache: true, // Optional. The default value is true.
priority: 1, // Optional. The default value is 1.
connectTimeout: 60000 // Optional. The default value is 60000, in ms.
readTimeout: 60000, // Optional. The default value is 60000, in ms.
usingProtocol: http.HttpProtocol.HTTP1_1, // Optional. The default protocol type is automatically specified by the system.
}, (err, data) => {
if (!err) {
// data.result contains the HTTP response. Parse the response based on service requirements.
// data.result carries the HTTP response. Parse the response based on service requirements.
console.info('Result:' + data.result);
console.info('code:' + data.responseCode);
// data.header contains the HTTP response header. Parse the content based on service requirements.
// data.header carries the HTTP response header. Parse the content based on service requirements.
console.info('header:' + JSON.stringify(data.header));
console.info('cookies:' + data.cookies); // 8+
} else {
......@@ -78,10 +82,9 @@ import http from '@ohos.net.http';
let httpRequest = http.createHttp();
```
## HttpRequest
HTTP request task. Before invoking APIs provided by **HttpRequest**, you must call [createHttp\(\)](#httpcreatehttp) to create an **HttpRequestTask** object.
Defines an HTTP request task. Before invoking APIs provided by **HttpRequest**, you must call [createHttp\(\)](#httpcreatehttp) to create an **HttpRequestTask** object.
### request
......@@ -89,7 +92,7 @@ request\(url: string, callback: AsyncCallback\<HttpResponse\>\):void
Initiates an HTTP request to a given URL. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
......@@ -121,7 +124,7 @@ request\(url: string, options: HttpRequestOptions, callback: AsyncCallback<HttpR
Initiates an HTTP request containing specified options to a given URL. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
......@@ -158,14 +161,13 @@ httpRequest.request("EXAMPLE_URL",
});
```
### request
request\(url: string, options? : HttpRequestOptions\): Promise<HttpResponse\>
Initiates an HTTP request to a given URL. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
......@@ -174,7 +176,7 @@ Initiates an HTTP request to a given URL. This API uses a promise to return the
| Name | Type | Mandatory| Description |
| ------- | ------------------ | ---- | ----------------------------------------------- |
| url | string | Yes | URL for initiating an HTTP request. |
| options | HttpRequestOptions | Yes | Request options. For details, see [HttpRequestOptions](#httprequestoptions).|
| options | HttpRequestOptions | No | Request options. For details, see [HttpRequestOptions](#httprequestoptions).|
**Return value**
......@@ -226,7 +228,7 @@ on\(type: 'headerReceive', callback: AsyncCallback<Object\>\): void
Registers an observer for HTTP Response Header events.
>![](public_sys-resources/icon-note.gif) **NOTE**
>**NOTE**
>This API has been deprecated. You are advised to use [on\('headersReceive'\)<sup>8+</sup>](#onheadersreceive8) instead.
**System capability**: SystemCapability.Communication.NetStack
......@@ -250,14 +252,13 @@ httpRequest.on('headerReceive', (err, data) => {
});
```
### off\('headerReceive'\)
off\(type: 'headerReceive', callback?: AsyncCallback<Object\>\): void
Unregisters the observer for HTTP Response Header events.
>![](public_sys-resources/icon-note.gif) **NOTE**
>**NOTE**
>
>1. This API has been deprecated. You are advised to use [off\('headersReceive'\)<sup>8+</sup>](#offheadersreceive8) instead.
>
......@@ -301,14 +302,13 @@ httpRequest.on('headersReceive', (header) => {
});
```
### off\('headersReceive'\)<sup>8+</sup>
off\(type: 'headersReceive', callback?: Callback<Object\>\): void
Unregisters the observer for HTTP Response Header events.
>![](public_sys-resources/icon-note.gif) **NOTE**
>**NOTE**
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -358,10 +358,14 @@ Specifies the type and value range of the optional parameters in the HTTP reques
| Name | Type | Mandatory| Description |
| -------------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| method | [RequestMethod](#requestmethod) | No | Request method. |
| extraData | string \| Object \| ArrayBuffer<sup>6+</sup> | No | Additional data of the request.<br>- If the HTTP request uses a POST or PUT method, this parameter serves as the content of the HTTP request.<br>- If the HTTP request uses a GET, OPTIONS, DELETE, TRACE, or CONNECT method, this parameter is a supplement to the HTTP request parameters and will be added to the URL when the request is sent.<sup>6+</sup><br>- To pass in a string object, you first need to encode the object on your own.<sup>8+</sup> |
| extraData | string \| Object \| ArrayBuffer<sup>6+</sup> | No | Additional data of the request.<br>- If the HTTP request uses a POST or PUT method, this parameter serves as the content of the HTTP request.<br>- If the HTTP request uses a GET, OPTIONS, DELETE, TRACE, or CONNECT method, this parameter is a supplement to the HTTP request parameters and will be added to the URL when the request is sent.<sup>6+</sup><br>- To pass in a string object, you first need to encode the object on your own.<sup>6+</sup> |
| expectDataType<sup>9+</sup> | [HttpDataType](#httpdatatype9) | No | Type of the return data. If this parameter is set, the system returns the specified type of data preferentially.|
| usingCache<sup>9+</sup> | boolean | No | Whether to use the cache. The default value is **true**. |
| priority<sup>9+</sup> | number | No | Priority. The value range is \[1,1000]. The default value is **1**. |
| header | Object | No | HTTP request header. The default value is **{'Content-Type': 'application/json'}**. |
| readTimeout | number | No | Read timeout duration. The default value is **60000**, in ms. |
| connectTimeout | number | No | Connection timeout interval. The default value is **60000**, in ms. |
| usingProtocol<sup>9+</sup> | [HttpProtocol](#httpprotocol9) | No | Protocol. The default value is automatically specified by the system. |
## RequestMethod
......@@ -371,14 +375,14 @@ Defines an HTTP request method.
| Name | Value | Description |
| :------ | ------- | :------------------ |
| OPTIONS | OPTIONS | OPTIONS method.|
| GET | GET | GET method. |
| HEAD | HEAD | HEAD method. |
| POST | POST | POST method. |
| PUT | PUT | PUT method. |
| DELETE | DELETE | DELETE method. |
| TRACE | TRACE | TRACE method. |
| CONNECT | CONNECT | CONNECT method.|
| OPTIONS | "OPTIONS" | OPTIONS method.|
| GET | "GET" | GET method. |
| HEAD | "HEAD" | HEAD method. |
| POST | "POST" | POST method. |
| PUT | "PUT" | PUT method. |
| DELETE | "DELETE" | DELETE method. |
| TRACE | "TRACE" | TRACE method. |
| CONNECT | "CONNECT" | CONNECT method.|
## ResponseCode
......@@ -388,7 +392,7 @@ Enumerates the response codes for an HTTP request.
| Name | Value | Description |
| ----------------- | ---- | ------------------------------------------------------------ |
| OK | 200 | Request succeeded. The request has been processed successfully. This return code is generally used for GET and POST requests. |
| OK | 200 | The request is successful. The request has been processed successfully. This return code is generally used for GET and POST requests. |
| CREATED | 201 | "Created." The request has been successfully sent and a new resource is created. |
| ACCEPTED | 202 | "Accepted." The request has been accepted, but the processing has not been completed. |
| NOT_AUTHORITATIVE | 203 | "Non-Authoritative Information." The request is successful. |
......@@ -433,17 +437,171 @@ Defines the response to an HTTP request.
| Name | Type | Mandatory| Description |
| -------------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| result | string \| Object \| ArrayBuffer<sup>6+</sup> | Yes | Response content returned based on **Content-type** in the response header:<br>- application/json: a string in JSON format. If you want to use specific content in the response, you need to implement parsing of that content.<br>- application/octet-stream: ArrayBuffer<br>- Others: string|
| resultType<sup>9+</sup> | [HttpDataType](#httpdatatype9) | Yes | Type of the return value. |
| responseCode | [ResponseCode](#responsecode) \| number | Yes | Result code for an HTTP request. If the callback function is successfully executed, a result code defined in [ResponseCode](#responsecode) will be returned. Otherwise, an error code will be returned in the **err** field in **AsyncCallback**. For details, see [Error Codes](#error-codes).|
| header | Object | Yes | Response header. The return value is a string in JSON format. If you want to use specific content in the response, you need to implement parsing of that content. Common fields and parsing methods are as follows:<br>- Content-Type: header['Content-Type'];<br>- Status-Line: header['Status-Line'];<br>- Date: header.Date/header['Date'];<br>- Server: header.Server/header['Server'];|
| cookies<sup>8+</sup> | Array\<string\> | Yes | Cookies returned by the server. |
## http.createHttpResponseCache<sup>9+</sup>
createHttpResponseCache(cacheSize?: number): HttpResponseCache
Creates a default object to store responses to HTTP access requests.
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| cacheSize | number | No| Cache size. The maximum value is 10\*1024\*1024 (10 MB). By default, the maximum value is used.|
**Return value**
| Type | Description |
| :---------- | :----------------------------------------------------------- |
| [HttpResponseCache](#httpresponsecache9) | Object that stores the response to the HTTP request.|
**Example**
```js
import http from '@ohos.net.http';
let httpResponseCache = http.createHttpResponseCache();
```
## HttpResponseCache<sup>9+</sup>
Defines an object that stores the response to an HTTP request.
### flush<sup>9+</sup>
flush(callback: AsyncCallback\<void>): void
Flushes data in the cache to the file system so that the cached data can be accessed in the next HTTP request. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
httpResponseCache.flush(err => {
if (err) {
console.log('flush fail');
return;
}
console.log('flush success');
});
```
### flush<sup>9+</sup>
flush(): Promise\<void>
Flushes data in the cache to the file system so that the cached data can be accessed in the next HTTP request. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<void>> | Promise used to return the result.|
**Example**
```js
httpResponseCache.flush().then(() => {
console.log('flush success');
}).catch(err => {
console.log('flush fail');
});
```
### delete<sup>9+</sup>
delete(callback: AsyncCallback\<void>): void
Disables the cache and deletes the data in it. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
httpResponseCache.delete(err => {
if (err) {
console.log('delete fail');
return;
}
console.log('delete success');
});
```
### delete<sup>9+</sup>
delete(): Promise\<void>
Disables the cache and deletes the data in it. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
httpResponseCache.delete().then(() => {
console.log('delete success');
}).catch(err => {
console.log('delete fail');
});
```
## Error Codes
| Error Code| Description |
| ------ | ------------------------------------------------------------ |
| -1 | Incorrect parameters. |
| 3 | Incorrect URL format. |
| 4 | Built-in request function, protocol, or option not found during build. |
| 5 | Unable to resolve the proxy. |
| 6 | Unable to resolve the host. |
| 7 | Unable to connect to the proxy or host. |
| -1 | Incorrect parameter. Check whether the number and type of parameters are correct. |
| 3 | Incorrect URL format. Check whether the format and syntax of the URL are correct. |
| 4 | Built-in request function, protocol, or option not found during build. If a function or option is not enabled or explicitly disabled, you need to rebuild a libcurl in order to access its functions. |
| 5 | Unable to resolve the proxy because of a failure to resolve the specified proxy server. You are advised perform the following: 1. Check whether the URL is correct. 2. Check whether the network connection is normal and whether the network can communicate with external networks. 3. Check whether the network access permission is available. |
| 6 | Unable to resolve the host because of a failure to resolve the specified remote host. You are advised perform the following: 1. Check whether the URL is correct. 2. Check whether the network connection is normal and whether the network can communicate with external networks. 3. Check whether the network access permission is available. |
| 7 | Unable to connect to the proxy or host. You are advised perform the following: 1. Check whether the port number is correct. 2. Check whether the HTTP proxy is enabled on the local host. |
## HttpDataType<sup>9+</sup>
Enumerates HTTP data types.
**System capability**: SystemCapability.Communication.NetStack
| Name| Value| Description |
| ------------------ | -- | ----------- |
| STRING | 0 | String type.|
| OBJECT | 1 | Object type. |
| ARRAY_BUFFER | 2 | Binary array type.|
## HttpProtocol<sup>9+</sup>
Enumerates HTTP protocol versions.
**System capability**: SystemCapability.Communication.NetStack
| Name | Description |
| :-------- | :----------- |
| HTTP1_1 | HTTP1.1 |
| HTTP2 | HTTP2 |
......@@ -16,7 +16,7 @@ import resourceManager from '@ohos.resourceManager';
## Instruction
Since API version 9, the stage model allows an application to obtain a **ResourceManager** object based on **context** and call its resource management APIs without first importing the required bundle. This approach, however, is not applicable to the FA model.
For details about how to reference **context** in the stage model, see [Context in the Stage Model](../../ability/context-userguide.md).
For details about how to reference **context** in the stage model, see [Context in the Stage Model].
```ts
import Ability from '@ohos.application.Ability';
......@@ -1375,15 +1375,16 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try {
this.context.resourceManager.getRawFd("test.xml", (error, value) => {
if (error != null) {
console.log("error is " + error);
console.log(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`);
} else {
let fd = value.fd;
let offset = value.offset;
let length = value.length;
}
}).catch(error => {
console.log("getRawFd callback error is " + error);
});
});
} catch (error) {
console.error(`callback getRawFd failed, error code: ${error.code}, message: ${error.message}.`)
};
```
### getRawFd<sup>9+</sup>
......@@ -1421,10 +1422,10 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
let offset = value.offset;
let length = value.length;
}).catch(error => {
console.log("getRawFd promise error is " + error);
console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`);
});
} catch (error) {
console.log("getRawFd promise error is " + error);
console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`);
};
```
......
# Geographic Location
> **NOTE**
> - The APIs of this module are no longer maintained since API version 7. You are advised to use [`@ohos.geolocation`](js-apis-geolocation.md).
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are no longer maintained since API version 9. You are advised to use [geoLocationManager](js-apis-geoLocationManager.md) instead.
## Modules to Import
......@@ -18,15 +18,12 @@ import geolocation from '@system.geolocation';
ohos.permission.LOCATION
## geolocation.getLocation<sup>(deprecated) </sup>
## geolocation.getLocation
getLocation(Object): void
Obtains the geographic location.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCurrentLocation](js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation).
**System capability**: SystemCapability.Location.Location.Lite
**Parameters**
......@@ -77,15 +74,12 @@ export default {
```
## geolocation.getLocationType<sup>(deprecated) </sup>
## geolocation.getLocationType
getLocationType(Object): void
Obtains the supported location types.
> **NOTE**
> This API is deprecated since API version 9.
**System capability**: SystemCapability.Location.Location.Lite
**Parameters**
......@@ -120,15 +114,12 @@ export default {
```
## geolocation.subscribe<sup>(deprecated) </sup>
## geolocation.subscribe
subscribe(Object): void
Listens to the geographical location. If this method is called multiple times, the last call takes effect.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('locationChange')](js-apis-geoLocationManager.md#geolocationmanageronlocationchange).
**System capability**: SystemCapability.Location.Location.Lite
**Parameters**
......@@ -175,15 +166,12 @@ export default {
```
## geolocation.unsubscribe<sup>(deprecated) </sup>
## geolocation.unsubscribe
unsubscribe(): void
Cancels listening to the geographical location.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('locationChange')](js-apis-geoLocationManager.md#geolocationmanagerofflocationchange).
**System capability**: SystemCapability.Location.Location.Lite
**Example**
......@@ -197,15 +185,12 @@ export default {
```
## geolocation.getSupportedCoordTypes<sup>(deprecated) </sup>
## geolocation.getSupportedCoordTypes
getSupportedCoordTypes(): Array&lt;string&gt;
Obtains coordinate system types supported by the device.
> **NOTE**
> This API is deprecated since API version 9.
**System capability**: SystemCapability.Location.Location.Lite
**Return Value**
......
......@@ -348,7 +348,7 @@ let ret = usb.getFileDescriptor(devicepipe);
## usb.controlTransfer
controlTransfer(pipe: USBDevicePipe, contrlparam: USBControlParams, timeout?: number): Promise&lt;number&gt;
controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout?: number): Promise&lt;number&gt;
Performs control transfer.
......@@ -361,7 +361,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pipe | [USBDevicePipe](#usbdevicepipe) | Yes| USB device pipe, which is used to determine the USB device.|
| contrlparam | [USBControlParams](#usbcontrolparams) | Yes| Control transfer parameters.|
| controlparam | [USBControlParams](#usbcontrolparams) | Yes| Control transfer parameters.|
| timeout | number | No| Timeout duration in ms. This parameter is optional. The default value is **0**, indicating no timeout.|
**Return value**
......
......@@ -9,7 +9,7 @@
| Ability | An abstraction of a functionality that an application can provide. It is the minimum unit for the system to schedule the application. An application can contain one or more **Ability** instances.|
| FA | Feature Ability, an ability that provides a UI for user interaction in the ability framework of the FA model. The FA supports only the Page ability template.|
| PA | Particle Ability, an ability that does not have a UI in the ability framework of the FA model. It provides services and support for FAs. For example, a PA can function as a background service to provide computing power or as a data store to provide data access capabilities. The PA supports three types of templates: Service, Data, and Form ability templates.|
| FA model | One of the two ability framework models. The FA model applies to application development using API version 8 and earlier versions. The FA model provides FAs and PAs. The FA supports the Page ability template, and the PA supports the Service, Data, and Form ability templates. For details, see [FA Model Overview](../../application-dev/ability/fa-brief.md).|
| FA model | One of the two ability framework models. The FA model applies to application development using API version 8 and earlier versions. The FA model provides FAs and PAs. The FA supports the Page ability template, and the PA supports the Service, Data, and Form ability templates. For details, see [FA Model Overview](../../application-dev/ability-deprecated/fa-brief.md).|
| Stage model| One of the two ability framework models. The stage model applies to application development using API version 9 and later versions. The stage model provides abilities and Extension abilities. The latter ones are extended to Service Extension abilities, Form Extension abilities, Data Share Extension abilities, and more.|
### Function
......
......@@ -48,9 +48,9 @@
```js
var locale = "zh-CN";
var options = {caseFirst: "false", calendar: "chinese", collation: "pinyin"};
var localeObj = new Intl.Locale(locale, options);
let locale = "zh-CN";
let options = {caseFirst: "false", calendar: "chinese", collation: "pinyin"};
let localeObj = new Intl.Locale(locale, options);
```
3. 获取Locale的字符串表示。
......@@ -58,7 +58,7 @@
调用toString方法来获取Locale对象的字符串表示,其中包括了语言、区域及其他选项信息。
```js
var localeStr = localeObj.toString(); // localeStr = "zh-CN-u-ca-chinese-co-pinyin-kf-false
let localeStr = localeObj.toString(); // localeStr = "zh-CN-u-ca-chinese-co-pinyin-kf-false
```
4. 最大化区域信息。
......@@ -66,8 +66,8 @@
调用maximize方法来最大化区域信息,即当缺少脚本与地区信息时,对其进行补全。
```js
var maximizedLocale = localeObj.maximize();
var maximizedLocaleStr = maximizedLocale.toString(); // localeStr = "zh-Hans-CN-u-ca-chinese-co-pinyin-kf-false
let maximizedLocale = localeObj.maximize();
let maximizedLocaleStr = maximizedLocale.toString(); // localeStr = "zh-Hans-CN-u-ca-chinese-co-pinyin-kf-false
```
5. 最小化区域信息。
......@@ -75,8 +75,8 @@
调用minimize方法来最小化区域信息,即当存在脚本与地区信息时,对其进行删除。
```js
var minimizedLocale = localeObj.minimize();
var minimizedLocaleStr = minimizedLocale.toString(); // zh-u-ca-chinese-co-pinyin-kf-false
let minimizedLocale = localeObj.minimize();
let minimizedLocaleStr = minimizedLocale.toString(); // zh-u-ca-chinese-co-pinyin-kf-false
```
## 格式化日期时间
......@@ -108,14 +108,14 @@
一种方法是使用DateTimeFormat提供的默认构造函数,通过访问系统语言和地区设置,获取系统默认Locale,并将其作为DateTimeFormat对象内部的Locale。
```js
var dateTimeFormat = new Intl.DateTimeFormat();
let dateTimeFormat = new Intl.DateTimeFormat();
```
另一种方法是使用开发者提供的Locale和格式化参数来创建日期时间格式化对象。其中,格式化参数是可选的,完整的格式化参数列表见[DateTimeOptions](../reference/apis/js-apis-intl.md#datetimeoptions)。
```js
var options = {dateStyle: "full", timeStyle: "full"};
var dateTimeFormat = new Intl.DateTimeFormat("zh-CN", options);
let options = {dateStyle: "full", timeStyle: "full"};
let dateTimeFormat = new Intl.DateTimeFormat("zh-CN", options);
```
3. 格式化日期时间。
......@@ -123,10 +123,10 @@
使用DateTimeFormat的format方法对一个Date对象进行格式化,该方法会返回一个字符串作为格式化的结果。
```js
var options = {dateStyle: "full", timeStyle: "full"};
var dateTimeFormat = new Intl.DateTimeFormat("zh-CN", options);
var date = new Date(2022, 12, 12, 12, 12, 12);
var formatResult = dateTimeFormat.format(date); // formatResult = "2023年1月12日星期四 中国标准时间 下午12:12:12"
let options = {dateStyle: "full", timeStyle: "full"};
let dateTimeFormat = new Intl.DateTimeFormat("zh-CN", options);
let date = new Date(2022, 12, 12, 12, 12, 12);
let formatResult = dateTimeFormat.format(date); // formatResult = "2023年1月12日星期四 中国标准时间 下午12:12:12"
```
4. 格式化时间段。
......@@ -134,10 +134,10 @@
使用DateTimeFormat的formatRange方法对一个时间段进行格式化。该方法需要传入两个Date对象,分别表示时间段的起止日期,返回一个字符串作为格式化的结果。
```js
var startDate = new Date(2021, 11, 17, 3, 24, 0);
var endDate = new Date(2021, 11, 18, 3, 24, 0);
var datefmt = new Intl.DateTimeFormat("en-GB");
var formatRangeResult = datefmt.formatRange(startDate, endDate); // formatRangeResult = "17/12/2021-18/12/2021"
let startDate = new Date(2021, 11, 17, 3, 24, 0);
let endDate = new Date(2021, 11, 18, 3, 24, 0);
let datefmt = new Intl.DateTimeFormat("en-GB");
let formatRangeResult = datefmt.formatRange(startDate, endDate); // formatRangeResult = "17/12/2021-18/12/2021"
```
5. 访问日期时间格式化对象的相关属性。
......@@ -145,9 +145,9 @@
DateTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了DateTimeFormat对象的所有相关属性及其值。
```js
var options = {dateStyle: "full", timeStyle: "full"};
var dateTimeFormat = new Intl.DateTimeFormat("zh-CN", options);
var resolvedOptions = dateTimeFormat.resolvedOptions(); // resolvedOptions = {"locale": "zh-CN", "calendar": "gregorian", "dateStyle":"full", "timeStyle":"full", "timeZone": "CST"}
let options = {dateStyle: "full", timeStyle: "full"};
let dateTimeFormat = new Intl.DateTimeFormat("zh-CN", options);
let resolvedOptions = dateTimeFormat.resolvedOptions(); // resolvedOptions = {"locale": "zh-CN", "calendar": "gregorian", "dateStyle":"full", "timeStyle":"full", "timeZone": "CST"}
```
## 数字格式化
......@@ -178,14 +178,14 @@
一种方法是使用NumberFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
```js
var numberFormat = new Intl.NumberFormat();
let numberFormat = new Intl.NumberFormat();
```
另一种方法是使用开发者提供的Locale和格式化参数来创建数字格式化对象。其中,格式化参数是可选的,完整的格式化参数列表参见[NumberOptions](../reference/apis/js-apis-intl.md#numberoptions)。
```js
var options = {compactDisplay: "short", notation: "compact"};
var numberFormat = new Intl.NumberFormat("zh-CN", options);
let options = {compactDisplay: "short", notation: "compact"};
let numberFormat = new Intl.NumberFormat("zh-CN", options);
```
3. 数字格式化。
......@@ -193,10 +193,10 @@
使用NumberFormat的format方法对传入的数字进行格式化。该方法返回一个字符串作为格式化的结果。
```js
var options = {compactDisplay: "short", notation: "compact"};
var numberFormat = new Intl.NumberFormat("zh-CN", options);
var number = 1234.5678
var formatResult = numberFormat.format(number); // formatResult = "1235"
let options = {compactDisplay: "short", notation: "compact"};
let numberFormat = new Intl.NumberFormat("zh-CN", options);
let number = 1234.5678
let formatResult = numberFormat.format(number); // formatResult = "1235"
```
4. 访问数字格式化对象的相关属性。
......@@ -204,9 +204,9 @@
NumberFormat的resolvedOptions方法会返回一个对象,该对象包含了NumberFormat对象的所有相关属性及其值。
```js
var options = {compactDisplay: "short", notation: "compact"};
var numberFormat = new Intl.NumberFormat("zh-CN", options);
var resolvedOptions = numberFormat.resolvedOptions(); // resolvedOptions = {"locale": "zh-CN", "compactDisplay": "short", "notation": "compact", "numberingSystem": "Latn"}
let options = {compactDisplay: "short", notation: "compact"};
let numberFormat = new Intl.NumberFormat("zh-CN", options);
let resolvedOptions = numberFormat.resolvedOptions(); // resolvedOptions = {"locale": "zh-CN", "compactDisplay": "short", "notation": "compact", "numberingSystem": "Latn"}
```
## 字符串排序
......@@ -237,14 +237,14 @@
一种方法是使用Collator提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
```js
var collator = new Intl.Collator();
let collator = new Intl.Collator();
```
另一种方法是使用开发者提供的Locale和其他相关参数来创建Collator对象,完整的参数列表参见[CollatorOptions](../reference/apis/js-apis-intl.md#collatoroptions9)。
其中,sensitivity参数用于控制哪些级别的差异会被用于比较两个字符串。取值"base"表示,仅比较字符本身,不考虑重音符号、大小写差异。例如,'a' != 'b','a' == 'á','a' == 'A'。取值"accent"表示考虑重音符号,不考虑大小写的差异。例如,'a' != 'b','a' != 'á','a' == 'A'。取值"case"表示考虑大小写的差异,不考虑重音符号的差异。例如,'a' != 'b','a' == 'á','a' != 'A'。取值"variant"表示考虑重音符号、大小写等方面差异。例如'a' != 'b','a' != 'á','a' != 'A'。
```js
var collator= new Intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort", sensitivity: "case"});
let collator= new Intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort", sensitivity: "case"});
```
3. 比较字符串。
......@@ -252,10 +252,10 @@
使用Collator的compare方法对传入的两个字符串进行比较。该方法返回一个数值作为比较的结果,返回-1表示第一个字符串小于第二个字符串,返回1表示第一个字符大于第二个字符串,返回0表示两个字符串相同。基于两个字符串的比较结果,开发者可以字符串集合进行排序。
```js
var collator= new Intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort", sensitivity: "case"});
var str1 = "first string";
var str2 = "second string";
var compareResult = collator.compare(str1, str2); // compareResult = -1
let collator= new Intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort", sensitivity: "case"});
let str1 = "first string";
let str2 = "second string";
let compareResult = collator.compare(str1, str2); // compareResult = -1
str1 = "first";
str2 = "First";
compareResult = collator.compare(str1, str2); // compareResult = -1
......@@ -266,8 +266,8 @@
Collator的resolvedOptions方法会返回一个对象,该对象包含了Collator对象的所有相关属性及其值。
```js
var collator= new Intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"});
var options = collator.resolvedOptions(); // options = {"localeMatcher": "best fit", "locale": "zh-CN", "usage": "sort", "sensitivity": "variant", "ignorePunctuation": "false", "numeric": false, "caseFirst": "false", "collation": "default"}
let collator= new Intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"});
let options = collator.resolvedOptions(); // options = {"localeMatcher": "best fit", "locale": "zh-CN", "usage": "sort", "sensitivity": "variant", "ignorePunctuation": "false", "numeric": false, "caseFirst": "false", "collation": "default"}
```
## 判定单复数类别
......@@ -298,13 +298,13 @@
一种方法是使用PluralRules提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
```js
var pluralRules = new Intl.PluralRules();
let pluralRules = new Intl.PluralRules();
```
另一种方法是使用开发者提供的Locale和其他相关参数来创建单复数对象。完整的参数列表参见[PluralRulesOptions](../reference/apis/js-apis-intl.md#pluralrulesoptions9)。
```js
var pluralRules = new Intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
let pluralRules = new Intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
```
3. 计算数字单复数类别。
......@@ -312,9 +312,9 @@
使用PluralRules的select方法计算传入数字的单复数类别。该方法返回一个字符串作为传入数字的类别,包括:"zero", "one", "two", "few", "many", "other"六个类别。
```js
var pluralRules = new Intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
var number = 1234.5678
var categoryResult = pluralRules.select(number); // categoryResult = "other"
let pluralRules = new Intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
let number = 1234.5678
let categoryResult = pluralRules.select(number); // categoryResult = "other"
```
## 相对时间格式化
......@@ -346,13 +346,13 @@
一种方法是使用RelativeTimeFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
```js
var relativeTimeFormat = new Intl.RelativeTimeFormat();
let relativeTimeFormat = new Intl.RelativeTimeFormat();
```
另一种方法是使用开发者提供的Locale和格式化参数来创建相对时间格式化对象。其中,格式化参数是可选的,完整的参数列表参见[ RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md#relativetimeformatinputoptions9)。
```js
var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
```
3. 相对时间格式化。
......@@ -360,10 +360,10 @@
使用RelativeTimeFormat的format方法对相对时间进行格式化。方法接收一个表示相对时间长度的数值和表示单位的字符串,其中单位包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。方法返回一个字符串作为格式化的结果。
```js
var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
var number = 2;
var unit = "year"
var formatResult = relativeTimeFormat.format(number, unit); // 2年后
let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
let number = 2;
let unit = "year"
let formatResult = relativeTimeFormat.format(number, unit); // 2年后
```
4. 获取相对时间格式化结果的各个部分。
......@@ -371,10 +371,10 @@
获取相对时间格式化结果的各个部分,从而自定义格式化结果。
```js
var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
var number = 2;
var unit = "year"
var formatPartsResult = relativeTimeFormat.formatToParts(number, unit); // formatPartsResult = [{"type": "integer", "value": "2", "unit": "year"}, {"type":"literal", "value": "年后"}]
let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
let number = 2;
let unit = "year"
let formatPartsResult = relativeTimeFormat.formatToParts(number, unit); // formatPartsResult = [{"type": "integer", "value": "2", "unit": "year"}, {"type":"literal", "value": "年后"}]
```
5. 访问相对时间格式化对象的相关属性。
......@@ -382,8 +382,8 @@
RelativeTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了RelativeTimeFormat对象的所有相关属性及其值,完整的属性列表参见[ RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md#relativetimeformatresolvedoptions8)。
```js
var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
var options = relativeTimeFormat.resolvedOptions(); // options = {"locale": "zh-CN", "style": "long", "numeric": "always", "numberingSystem": "latn"}
let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
let options = relativeTimeFormat.resolvedOptions(); // options = {"locale": "zh-CN", "style": "long", "numeric": "always", "numberingSystem": "latn"}
```
## 相关实例
......
......@@ -14,7 +14,7 @@ import wantConstant from '@ohos.ability.wantConstant';
## wantConstant.Action
want操作的常数。
want操作的常数。用于表示要执行的通用操作。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
......@@ -57,13 +57,13 @@ want操作的常数。
## wantConstant.Entity
want实体的常数。
want实体的常数。用于表示目标Ability额外的类别信息。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
| 名称 | 值 | 说明 |
| ------------ | ------------------ | ---------------------- |
| ENTITY_DEFAULT | entity.system.default | 指示默认实体,如果未指定实体,则使用该实体。 |
| ENTITY_DEFAULT | entity.system.default | 指示默认实体,如果未指定实体,则使用该实体。 |
| ENTITY_HOME | entity.system.home | 指示主屏幕实体。 |
| ENTITY_VOICE | entity.system.voice | 表示语音交互实体。 |
| ENTITY_BROWSABLE | entity.system.browsable | 指示浏览器类别。 |
......@@ -72,7 +72,7 @@ want实体的常数。
## wantConstant.Flags
Flags说明。
Flags说明。用于表示处理Want的方式。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
......
......@@ -385,7 +385,6 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // 可以通过getApplicationInfo获取accessTokenId
let permissionFlag = 1;
try {
atManager.getPermissionFlags(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS").then((data) => {
console.log(`getPermissionFlags success, data->${JSON.stringify(data)}`);
......@@ -459,11 +458,12 @@ on(type: 'permissionStateChange', tokenIDList: Array&lt;number&gt;, permissionNa
**示例:**
```js
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
let tokenIDList: Array<number> = [];
let permissionNameList = [];
let appInfo = bundle.getApplicationInfoSync('com.example.myapplication', 0, 100);
let tokenIDList: Array<number> = [appInfo.accessTokenId];
let permissionNameList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"];
try {
atManager.on('permissionStateChange', tokenIDList, permissionNameList, (data) => {
console.debug("receive permission state change, data:" + JSON.stringify(data));
......@@ -508,11 +508,12 @@ off(type: 'permissionStateChange', tokenIDList: Array&lt;number&gt;, permissionN
**示例:**
```js
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
let tokenIDList: Array<number> = [];
let permissionNameList = [];
let appInfo = bundle.getApplicationInfoSync('com.example.myapplication', 0, 100);
let tokenIDList: Array<number> = [appInfo.accessTokenId];
let permissionNameList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"];
try {
atManager.off('permissionStateChange', tokenIDList, permissionNameList);
} catch(err) {
......
......@@ -16,7 +16,7 @@ import Configuration from '@ohos.app.ability.Configuration'
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| language | string | 是 | 是 | 表示应用程序的当前语言。 |
| language | string | 是 | 是 | 表示应用程序的当前语言。例如:zh。 |
| colorMode | [ColorMode](js-apis-app-ability-configurationConstant.md#configurationconstantcolormode) | 是 | 是 | 表示深浅色模式,取值范围:浅色模式(COLOR_MODE_LIGHT),深色模式(COLOR_MODE_DARK)。默认为浅色。 |
| direction | [Direction](js-apis-app-ability-configurationConstant.md#configurationconstantdirection) | 是 | 否 | 表示屏幕方向,取值范围:水平方向(DIRECTION_HORIZONTAL),垂直方向(DIRECTION_VERTICAL)。 |
| screenDensity | [ScreenDensity](js-apis-app-ability-configurationConstant.md#configurationconstantscreendensity) | 是 | 否 | 表示屏幕分辨率,取值范围:SCREEN_DENSITY_SDPI(120)、SCREEN_DENSITY_MDPI(160)、SCREEN_DENSITY_LDPI(240)、SCREEN_DENSITY_XLDPI(320)、SCREEN_DENSITY_XXLDPI(480)、SCREEN_DENSITY_XXXLDPI(640)。 |
......@@ -40,7 +40,7 @@ import Configuration from '@ohos.app.ability.Configuration'
}
};
try {
var callbackId = applicationContext.on("environment", envCallback);
let callbackId = applicationContext.on("environment", envCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
......
......@@ -18,23 +18,23 @@ import Want from '@ohos.app.ability.Want';
| 名称 | 类型 | 必填 | 说明 |
| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId | string | 否 | 表示运行指定Ability的设备ID。 |
| bundleName | string | 否 | 表示包描述。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 |
| deviceId | string | 否 | 表示运行指定Ability的设备ID。如果未设置该字段,则表明指定本设备。 |
| bundleName | string | 否 | 表示Bundle名称。 |
| abilityName | string | 否 | 表示待启动的Ability名称。如果在Want中该字段同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。AbilityName需要在一个应用的范围内保证唯一。 |
| uri | string | 否 | 表示Uri描述。如果在Want中指定了Uri,则Want将匹配指定的Uri信息,包括scheme, schemeSpecificPart, authority和path信息。 |
| type | string | 否 | 表示MIME type类型描述,打开文件的类型,主要用于文管打开文件。比如:"text/xml" 、 "image/*"等,MIME定义参考:https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com。 |
| flags | number | 否 | 表示处理Want的方式。默认传数字,具体参考:[flags说明](js-apis-app-ability-wantConstant.md#wantConstant.Flags)。 |
| action | string | 否 | 表示要执行的通用操作(如:查看、分享、应用详情)。在隐式Want中,您可以定义该字段,配合uri或parameters来表示对数据要执行的操作。 |
| action | string | 否 | 表示要执行的通用操作(如:查看、分享、应用详情)。在隐式Want中,您可以定义该字段,配合uri或parameters来表示对数据要执行的操作。具体参考:[action说明](js-apis-app-ability-wantConstant.md#wantConstant.Action)。隐式Want定义及匹配规则参考:[显式Want与隐式Want匹配规则](application-models/explicit-implicit-want-mappings.md) |
| parameters | {[key: string]: any} | 否 | 表示WantParams描述,由开发者自行决定传入的键值对。默认会携带以下key值:<br>ohos.aafwk.callerPid 表示拉起方的pid。<br>ohos.aafwk.param.callerToken 表示拉起方的token。<br>ohos.aafwk.param.callerUid 表示[bundleInfo](js-apis-bundleManager-bundleInfo.md#bundleinfo-1)中的uid,应用包里应用程序的uid。 |
| entities | Array\<string> | 否 | 表示目标Ability额外的类别信息(如:浏览器、视频播放器),在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。 |
| entities | Array\<string> | 否 | 表示目标Ability额外的类别信息(如:浏览器、视频播放器)。在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。具体参考:[entity说明](js-apis-app-ability-wantConstant.md#wantConstant.Entity)。 |
| moduleName | string | 否 | 表示待启动的Ability所属的模块(module)。 |
**示例:**
- 基础用法
- 基础用法(在UIAbility对象中调用,其中示例中的context为UIAbility的上下文对象)
```ts
var want = {
let want = {
"deviceId": "", // deviceId为空表示本设备
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
......@@ -46,7 +46,7 @@ import Want from '@ohos.app.ability.Want';
})
```
- 通过自定字段传递数据, 以下为当前支持类型。
- 通过自定字段传递数据, 以下为当前支持类型。(在UIAbility对象中调用,其中示例中的context为UIAbility的上下文对象)
* 字符串(String)
```ts
......@@ -110,13 +110,13 @@ import Want from '@ohos.app.ability.Want';
* 文件描述符(FD)
```ts
import fileio from '@ohos.fileio';
var fd;
let fd;
try {
fd = fileio.openSync("/data/storage/el2/base/haps/pic.png");
} catch(e) {
console.log("openSync fail:" + JSON.stringify(e));
}
var want = {
let want = {
"deviceId": "", // deviceId为空表示本设备
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
......@@ -131,6 +131,8 @@ import Want from '@ohos.app.ability.Want';
})
```
- 更多详细说明和示例请参见: [应用模型](../../application-models/Readme-CN.md)的信息传递载体Want
<!--no_check-->
......@@ -14,7 +14,7 @@ import wantConstant from '@ohos.app.ability.wantConstant';
## wantConstant.Action
want操作的常数。
want操作的常数。用于表示要执行的通用操作。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
......@@ -56,7 +56,7 @@ want操作的常数。
## wantConstant.Entity
want实体的常数。
want实体的常数。用于表示目标Ability额外的类别信息。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
......@@ -71,7 +71,7 @@ want实体的常数。
## wantConstant.Flags
Flags说明。
Flags说明。用于表示处理Want的方式。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
......
......@@ -16,7 +16,7 @@ import Configuration from '@ohos.application.Configuration'
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| language<sup>8+</sup> | string | 是 | 是 | 表示应用程序的当前语言。 |
| language<sup>8+</sup> | string | 是 | 是 | 表示应用程序的当前语言。例如:zh。 |
| colorMode<sup>8+</sup> | [ColorMode](js-apis-application-configurationConstant.md#configurationconstantcolormode) | 是 | 是 | 表示深浅色模式,取值范围:浅色模式(COLOR_MODE_LIGHT),深色模式(COLOR_MODE_DARK)。默认为浅色。 |
| direction<sup>9+</sup> | [Direction](js-apis-application-configurationConstant.md#configurationconstantdirection9) | 是 | 否 | 表示屏幕方向,取值范围:水平方向(DIRECTION_HORIZONTAL),垂直方向(DIRECTION_VERTICAL)。 |
| screenDensity<sup>9+</sup> | [ScreenDensity](js-apis-application-configurationConstant.md#configurationconstantscreendensity9) | 是 | 否 | 表示屏幕分辨率,取值范围:SCREEN_DENSITY_SDPI(120)、SCREEN_DENSITY_MDPI(160)、SCREEN_DENSITY_LDPI(240)、SCREEN_DENSITY_XLDPI(320)、SCREEN_DENSITY_XXLDPI(480)、SCREEN_DENSITY_XXXLDPI(640)。 |
......
......@@ -18,23 +18,23 @@ import Want from '@ohos.application.Want';
| 名称 | 类型 | 必填 | 说明 |
| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId | string | 否 | 表示运行指定Ability的设备ID。 |
| bundleName | string | 否 | 表示包描述。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 |
| deviceId | string | 否 | 表示运行指定Ability的设备ID。如果未设置该字段,则表明指定本设备。 |
| bundleName | string | 否 | 表示Bundle名称。 |
| abilityName | string | 否 | 表示待启动的Ability名称。如果在Want中该字段同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。AbilityName需要在一个应用的范围内保证唯一。 |
| uri | string | 否 | 表示Uri描述。如果在Want中指定了Uri,则Want将匹配指定的Uri信息,包括scheme, schemeSpecificPart, authority和path信息。 |
| type | string | 否 | 表示MIME type类型描述,打开文件的类型,主要用于文管打开文件。比如:"text/xml" 、 "image/*"等,MIME定义参考:https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com。 |
| flags | number | 否 | 表示处理Want的方式。默认传数字,具体参考:[flags说明](js-apis-ability-wantConstant.md#wantConstant.Flags)。 |
| action | string | 否 | 表示要执行的通用操作(如:查看、分享、应用详情)。在隐式Want中,您可以定义该字段,配合uri或parameters来表示对数据要执行的操作。 |
| action | string | 否 | 表示要执行的通用操作(如:查看、分享、应用详情)。在隐式Want中,您可以定义该字段,配合uri或parameters来表示对数据要执行的操作。具体参考:[action说明](js-apis-app-ability-wantConstant.md#wantConstant.Action)。隐式Want定义及匹配规则参考:[显式Want与隐式Want匹配规则](application-models/explicit-implicit-want-mappings.md) |
| parameters | {[key: string]: any} | 否 | 表示WantParams描述,由开发者自行决定传入的键值对。默认会携带以下key值:<br>ohos.aafwk.callerPid 表示拉起方的pid。<br>ohos.aafwk.param.callerToken 表示拉起方的token。<br>ohos.aafwk.param.callerUid 表示[bundleInfo](js-apis-bundle-BundleInfo.md#bundleinfo-1)中的uid,应用包里应用程序的uid。 |
| entities | Array\<string> | 否 | 表示目标Ability额外的类别信息(如:浏览器、视频播放器),在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。 |
| entities | Array\<string> | 否 | 表示目标Ability额外的类别信息(如:浏览器、视频播放器)。在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。具体参考:[entity说明](js-apis-app-ability-wantConstant.md#wantConstant.Entity)。 |
| moduleName<sup>9+</sup> | string | 否 | 表示待启动的Ability所属的模块(module)。 |
**示例:**
- 基础用法
- 基础用法(在UIAbility对象中调用,其中示例中的context为UIAbility的上下文对象)
```ts
var want = {
let want = {
"deviceId": "", // deviceId为空表示本设备
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
......@@ -46,7 +46,7 @@ import Want from '@ohos.application.Want';
})
```
- 通过自定字段传递数据, 以下为当前支持类型。
- 通过自定字段传递数据, 以下为当前支持类型。(在UIAbility对象中调用,其中示例中的context为UIAbility的上下文对象)
* 字符串(String)
```ts
......@@ -110,13 +110,13 @@ import Want from '@ohos.application.Want';
* 文件描述符(FD)
```ts
import fileio from '@ohos.fileio';
var fd;
let fd;
try {
fd = fileio.openSync("/data/storage/el2/base/haps/pic.png");
} catch(e) {
console.log("openSync fail:" + JSON.stringify(e));
}
var want = {
let want = {
"deviceId": "", // deviceId为空表示本设备
"bundleName": "com.extreme.test",
"abilityName": "MainAbility",
......@@ -131,4 +131,6 @@ import Want from '@ohos.application.Want';
})
```
- 更多详细说明和示例请参见: [应用模型](../../application-models/Readme-CN.md)的信息传递载体Want
<!--no_check-->
\ No newline at end of file
......@@ -18,8 +18,8 @@ Ability信息,未做特殊说明的属性,均通过[bundle.getAbilityInfo](j
| label | string | 是 | 否 | Ability对用户显示的名称。 |
| description | string | 是 | 否 | Ability的描述。 |
| icon | string | 是 | 否 | Ability的图标资源文件索引。 |
| descriptionId | number | 是 | 否 | Ability的描述id。 |
| iconId | number | 是 | 否 | Ability的图标id。 |
| descriptionId | number | 是 | 否 | Ability的描述的资源id值。 |
| iconId | number | 是 | 否 | Ability的图标的资源id值。 |
| moduleName | string | 是 | 否 | Ability所属的HAP的名称。 |
| process | string | 是 | 否 | Ability的进程,如果不设置,默认为包的名称。 |
| targetAbility | string | 是 | 否 | 当前Ability重用的目标Ability。<br />此属性仅可在FA模型下使用。 |
......@@ -36,7 +36,7 @@ Ability信息,未做特殊说明的属性,均通过[bundle.getAbilityInfo](j
| writePermission | string | 是 | 否 | 向Ability写数据所需的权限。<br />此属性仅可在FA模型下使用。 |
| applicationInfo | [ApplicationInfo](js-apis-bundle-ApplicationInfo.md) | 是 | 否 | 应用程序的配置信息。<br />通过调用[bundle.getAbilityInfo](js-apis-Bundle.md#bundlegetabilityinfodeprecated)接口时,传入GET_ABILITY_INFO_WITH_APPLICATION获取。 |
| uri | string | 是 | 否 | 获取Ability的统一资源标识符(URI)。<br />此属性仅可在FA模型下使用。 |
| labelId | number | 是 | 否 | Ability的标签id。 |
| labelId | number | 是 | 否 | Ability的标签的资源id值。 |
| subType | AbilitySubType | 是 | 否 | Ability中枚举使用的模板的子类型。<br />此属性仅可在FA模型下使用。 |
| metadata<sup>8+</sup> | Array\<[CustomizeData](js-apis-bundle-CustomizeData.md)> | 是 | 否 | ability的元信息。<br />通过调用[bundle.getAbilityInfo](js-apis-Bundle.md#bundlegetabilityinfodeprecated)接口时,传入GET_ABILITY_INFO_WITH_METADATA获取。 |
| enabled<sup>8+</sup> | boolean | 是 | 否 | ability是否可用。 |
......@@ -17,8 +17,8 @@ ElementName信息,标识Ability的基本信息,通过接口[Context.getEleme
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------------------- | ---------| ---- | ---- | ------------------------- |
| deviceId | string | 是 | 是 | 设备id。 |
| bundleName | string | 是 | 是 | 应用Bundle名称。 |
| abilityName | string | 是 | 是 | Ability名称。 |
| deviceId | string | 是 | 是 | 设备id。 |
| bundleName | string | 是 | 是 | 应用Bundle名称。 |
| abilityName | string | 是 | 是 | Ability名称。 |
| uri | string | 是 | 是 | 资源标识符。 |
| shortName | string | 是 | 是 | Ability短名称。 |
\ No newline at end of file
| shortName | string | 是 | 是 | Ability的短名称。 |
\ No newline at end of file
......@@ -17,7 +17,7 @@ LauncherAbilityInfo信息,通过接口[innerBundleManager.getLauncherAbilityIn
| --------------- | ---------------------------------------------------- | ---- | ---- | -------------------------------------- |
| applicationInfo | [ApplicationInfo](js-apis-bundle-ApplicationInfo.md) | 是 | 否 | launcher ability的应用程序的配置信息。 |
| elementName | [ElementName](js-apis-bundle-ElementName.md) | 是 | 否 | launcher ability的ElementName信息。 |
| labelId | number | 是 | 否 | launcher ability的标签ID。 |
| iconId | number | 是 | 否 | launcher ability的图标ID。 |
| userId | number | 是 | 否 | launcher ability的用户ID。 |
| labelId | number | 是 | 否 | launcher ability的标签的资源id值。 |
| iconId | number | 是 | 否 | launcher ability的图标的资源id值。 |
| userId | number | 是 | 否 | launcher ability的用户的资源id值。 |
| installTime | number | 是 | 否 | launcher ability的安装时间。 |
\ No newline at end of file
......@@ -13,17 +13,17 @@ HAP信息,系统应用可以通过[bundleManager.getBundleInfo](js-apis-bundle
| --------------------------------- | ------------------------------------------------------------ | ---- | ---- | -------------------- |
| name | string | 是 | 否 | 模块名称。 |
| icon | string | 是 | 否 | 模块图标。 |
| iconId | number | 是 | 否 | 模块图标资源id。 |
| iconId | number | 是 | 否 | 模块图标的资源id值。 |
| label | string | 是 | 否 | 模块标签。 |
| labelId | number | 是 | 否 | 模块标签资源id。 |
| labelId | number | 是 | 否 | 模块标签的资源id值。 |
| description | string | 是 | 否 | 模块描述信息。 |
| descriptionId | number | 是 | 否 | 描述信息资源id。 |
| descriptionId | number | 是 | 否 | 描述信息的资源id值。 |
| mainElementName | string | 是 | 否 | 入口ability信息。 |
| abilitiesInfo | Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)> | 是 | 否 | Ability信息。 |
| extensionAbilitiesInfo | Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> | 是 | 否 | ExtensionAbility信息。 |
| metadata | Array\<[Metadata](js-apis-bundleManager-metadata.md)> | 是 | 否 | Ability的元信息。 |
| deviceTypes | Array\<string> | 是 | 否 | 支持运行的设备类型。 |
| installationFree | boolean | 是 | 否 | 是否支持免安装。 |
| hashValue | string | 是 | 否 | Module的Hash值。 |
| moduleSourceDir | string | 是 | 否 | Module的路径。|
| deviceTypes | Array\<string> | 是 | 否 | 可以运行模块的设备类型。 |
| installationFree | boolean | 是 | 否 | 模块是否支持免安装。 |
| hashValue | string | 是 | 否 | 模块的Hash值。 |
| moduleSourceDir | string | 是 | 否 | 模块的路径。|
......@@ -81,7 +81,7 @@ off(type: BundleChangedEvent, callback?: callback\<BundleChangedInfo>): void;
| 参数名 | 类型 | 必填 | 说明 |
| ---------------------------- | -------- | ---- | ---------------------------------------------------------- |
| type| BundleChangedEvent| 是 | 注销监听的事件类型。 |
| callback | callback\<BundleChangedInfo>| | 注销监听的回调函数,当为空时表示注销当前事件的所有callback。 |
| callback | callback\<BundleChangedInfo>| | 注销监听的回调函数,当为空时表示注销当前事件的所有callback。 |
**示例:**
......
......@@ -67,13 +67,13 @@ try {
abilityName: 'MainAbility'
}, (err, data) => {
if (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
} else {
console.info('Operation succeed:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
}
```
......@@ -124,10 +124,10 @@ try {
}).then(data => {
console.info('Operation succeed:' + JSON.stringify(data));
}).catch(err => {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
});
} catch (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
}
```
......@@ -179,13 +179,13 @@ try {
}
], (err, data) => {
if (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
} else {
console.info('Operation succeed:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
}
```
......@@ -243,10 +243,10 @@ try {
]).then(data => {
console.info('Operation succeed:' + JSON.stringify(data));
}).catch(err => {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
});
} catch (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
}
```
......@@ -292,13 +292,13 @@ try {
abilityName: 'MainAbility'
}, 'zh-Hans-CN', (err, data) => {
if (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
} else {
console.info('Operation succeed:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
}
```
......@@ -350,10 +350,10 @@ try {
}, 'zh-Hans-CN').then(data => {
console.info('Operation succeed:' + JSON.stringify(data));
}).catch(err => {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
});
} catch (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
}
```
......@@ -406,13 +406,13 @@ try {
}
], 'zh-Hans-CN', (err, data) => {
if (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
} else {
console.info('Operation succeed:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
}
```
......@@ -471,9 +471,9 @@ try {
], 'zh-Hans-CN').then(data => {
console.info('Operation succeed:' + JSON.stringify(data));
}).catch(err => {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
});
} catch (err) {
console.error('Operation failed: error code is ' + err.code + 'and error message is ' + err.message);
console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`);
}
```
......@@ -70,7 +70,7 @@ createFileAccessHelper(context: Context, wants: Array&lt;Want&gt;) : FileAccessH
```js
createFileAccessHelper() {
let fileAccesssHelper = null;
let fileAccessHelper = null;
// wantInfos 从getFileAccessAbilityInfo()获取
// 创建只连接媒体库服务的helper对象
let wantInfos = [
......@@ -81,8 +81,8 @@ createFileAccessHelper(context: Context, wants: Array&lt;Want&gt;) : FileAccessH
]
try {
// this.context 是MainAbility 传过来的context
fileAccesssHelper = fileAccess.createFileAccessHelper(this.context, wantInfos);
if (!fileAccesssHelper)
fileAccessHelper = fileAccess.createFileAccessHelper(this.context, wantInfos);
if (!fileAccessHelper)
console.error("createFileAccessHelper interface returns an undefined object");
} catch (error) {
console.error("createFileAccessHelper failed, error " + error);
......@@ -154,6 +154,7 @@ getRoots( ) : Promise&lt;RootIterator&gt;
let rootinfos = [];
let isDone = false;
try {
// fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
rootIterator = await fileAccessHelper.getRoots();
if (!rootIterator) {
console.error("getRoots interface returns an undefined object");
......@@ -248,26 +249,26 @@ scanFile(filter?: Filter) : FileIterator
**示例:**
```js
// rootinfos 从 getRoots()获取
// rootInfos 从 getRoots()获取
// let filter = {suffix : [".txt", ".jpg", ".xlsx"]};
let rootInfo = rootinfos[0];
let rootInfo = rootInfos[0];
let fileInfos = [];
let isDone = false;
try {
let fileIterator = rootInfo.scanFile();
// 含过滤器实现的scanFile
// let fileIterator = rootInfo.scanFile(filter);
if (!fileIterator) {
console.error("scanFile interface returns undefined object");
return;
}
while (!isDone) {
let result = fileIterator.next();
console.log("next result = " + JSON.stringify(result));
isDone = result.done;
if (!isDone)
fileInfos.push(result.value);
}
let fileIterator = rootInfo.scanFile();
// 含过滤器实现的scanFile
// let fileIterator = rootInfo.scanFile(filter);
if (!fileIterator) {
console.error("scanFile interface returns undefined object");
return;
}
while (!isDone) {
let result = fileIterator.next();
console.log("next result = " + JSON.stringify(result));
isDone = result.done;
if (!isDone)
fileInfos.push(result.value);
}
} catch (error) {
console.error("scanFile failed, error " + error);
}
......@@ -364,7 +365,7 @@ scanFile(filter?: Filter) : FileIterator;
}
while (!isDone) {
let result = fileIterator.next();
console.error("next result = " + JSON.stringify(result));
console.log("next result = " + JSON.stringify(result));
isDone = result.done;
if (!isDone)
subfileInfos.push(result.value);
......@@ -407,6 +408,7 @@ createFile(uri: string, displayName: string) : Promise&lt;string&gt;
let displayName = "file1"
let fileUri = null;
try {
// fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
fileUri = await fileAccessHelper.createFile(sourceUri, displayName)
if (!fileUri) {
console.error("createFile return undefined object");
......@@ -451,6 +453,7 @@ mkDir(parentUri: string, displayName: string) : Promise&lt;string&gt;
let dirName = "dirTest"
let dirUri = null;
try {
// fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
dirUri = await fileAccessHelper.mkDir(sourceUri, dirName)
if (!dirUri) {
console.error("mkDir return undefined object");
......@@ -483,7 +486,7 @@ openFile(uri: string, flags: OPENFLAGS) : Promise&lt;number&gt;
| 类型 | 说明 |
| --- | -- |
| Promise&lt;number&gt | 文件句柄 |
| Promise&lt;number&gt; | 文件句柄 |
**示例:**
......@@ -493,7 +496,8 @@ openFile(uri: string, flags: OPENFLAGS) : Promise&lt;number&gt;
// 开发者应根据自己实际获取的uri进行开发
let targetUri = "datashare:///media/file/100";
try {
let fd = await fileAccessHelper.openFile(targetUri, OPENFLAGS.READ);
// fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
let fd = await fileAccessHelper.openFile(targetUri, fileAccess.OPENFLAGS.READ);
} catch (error) {
console.error("openFile failed, error " + error);
};
......@@ -529,6 +533,7 @@ delete(uri: string) : Promise&lt;number&gt;
// 开发者应根据自己实际获取的uri进行开发
let targetUri = "datashare:///media/file/100";
try {
// fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
let code = await fileAccessHelper.delete(targetUri);
if (code != 0)
console.error("delete failed, code " + code);
......@@ -569,6 +574,7 @@ move(sourceFile: string, destFile: string) : Promise&lt;string&gt;
let sourceFile = "datashare:///media/file/102";
let destFile = "datashare:///media/file/101";
try {
// fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
let fileUri = await fileAccessHelper.move(sourceFile, destFile);
console.log("move sucess, fileUri: " + JSON.stringify(fileUri));
} catch (error) {
......@@ -607,6 +613,7 @@ rename(uri: string, displayName: string) : Promise&lt;string&gt;
// 开发者应根据自己实际获取的uri进行开发
let sourceDir = "datashare:///media/file/100";
try {
// fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
let DestDir = await fileAccessHelper.rename(sourceDir, "testDir");
console.log("rename sucess, DestDir: " + JSON.stringify(DestDir));
} catch (error) {
......@@ -644,6 +651,7 @@ access(sourceFileUri: string) : Promise&lt;boolean&gt;
// 开发者应根据自己实际获取的uri进行开发
let sourceDir = "datashare:///media/file/100";
try {
// fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
let existJudgment = await fileAccessHelper.access(sourceDir);
if (existJudgment)
console.log("sourceDir exists");
......
......@@ -39,8 +39,8 @@ import fileExtensionInfo from '@ohos.fileExtensionInfo';
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------ | ------ | ---- | ---- | -------- |
| SUPPORTS_READ | number | 是 | 否 | 支持读 |
| SUPPORTS_WRITE | number | 是 | 否 | 支持写 |
| SUPPORTS_READ | number | 是 | 否 | 此设备支持读 |
| SUPPORTS_WRITE | number | 是 | 否 | 此设备支持写 |
## fileExtensionInfo.DocumentFlag
......@@ -54,5 +54,5 @@ import fileExtensionInfo from '@ohos.fileExtensionInfo';
| ------ | ------ | ---- | ---- | -------- |
| REPRESENTS_FILE | number | 是 | 否 | 代表文件 |
| REPRESENTS_DIR | number | 是 | 否 | 代表目录 |
| SUPPORTS_READ | number | 是 | 否 | 支持读 |
| SUPPORTS_WRITE | number | 是 | 否 | 支持写 |
| SUPPORTS_READ | number | 是 | 否 | 此文件支持读 |
| SUPPORTS_WRITE | number | 是 | 否 | 此文件支持写 |
......@@ -10,15 +10,15 @@ Want是对象间信息传递的载体, 可以用于应用组件间的信息传
| 名称 | 类型 | 必填 | 说明 |
| ----------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId | string | 否 | 表示运行指定Ability的设备ID。 |
| bundleName | string | 否 | 表示Bundle名称。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 |
| deviceId | string | 否 | 表示运行指定Ability的设备ID。如果未设置该字段,则表明指定本设备。 |
| bundleName | string | 否 | 表示Bundle名称。 |
| abilityName | string | 否 | 表示待启动的Ability名称。如果在Want中该字段同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。AbilityName需要在一个应用的范围内保证唯一。 |
| uri | string | 否 | 表示Uri。如果在Want中指定了Uri,则Want将匹配指定的Uri信息,包括scheme, schemeSpecificPart, authority和path信息。 |
| type | string | 否 | 表示MIME type类型,打开文件的类型,主要用于文管打开文件。比如:"text/xml" 、 "image/*"等,MIME定义参考:https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com。 |
| flags | number | 否 | 表示处理Want的方式。默认传数字,具体参考:[flags说明](js-apis-ability-wantConstant.md#wantConstant.Flags)。 |
| action | string | 否 | 表示要执行的通用操作(如:查看、分享、应用详情)。在隐式Want中,您可以定义该字段,配合uri或parameters来表示对数据要执行的操作。 |
| action | string | 否 | 表示要执行的通用操作(如:查看、分享、应用详情)。在隐式Want中,您可以定义该字段,配合uri或parameters来表示对数据要执行的操作。具体参考:[action说明](js-apis-app-ability-wantConstant.md#wantConstant.Action)。隐式Want定义及匹配规则参考:[显式Want与隐式Want匹配规则](application-models/explicit-implicit-want-mappings.md) |
| parameters | {[key: string]: any} | 否 | 表示WantParams,由开发者自行决定传入的键值对。默认会携带以下key值:<br>ohos.aafwk.callerPid 表示拉起方的pid。<br>ohos.aafwk.param.callerToken 表示拉起方的token。<br>ohos.aafwk.param.callerUid 表示[bundleInfo](js-apis-bundle-BundleInfo.md#bundleinfo-1)中的uid,应用包里应用程序的uid。 |
| entities | Array\<string> | 否 | 表示目标Ability额外的类别信息(如:浏览器、视频播放器),在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。 |
| entities | Array\<string> | 否 | 表示目标Ability额外的类别信息(如:浏览器、视频播放器),在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。具体参考:[entity说明](js-apis-app-ability-wantConstant.md#wantConstant.Entity) |
| moduleName<sup>9+</sup> | string | 否 | 表示待启动的Ability所属的模块(module)。 |
**示例:**
......
......@@ -10,8 +10,8 @@
## 导入模块
```
import configuration from '@system.configuration';
```ts
import Configuration from '@system.configuration';
```
......
......@@ -2343,7 +2343,7 @@ async function example() {
**系统能力:** 以下各项对应的系统能力均为SystemCapability.FileManagement.UserFileManager.Core
| 名称 | 类型 | 可读 | 可写 说明 |
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ----- | ---- | ---- | ---- | ---- |
| deviceChange | string | 是 | 是 | 设备 |
| albumChange | string | 是 | 是 | 相册 |
......
......@@ -6,12 +6,17 @@
libuv是一个跨平台库,基于事件驱动来实现异步I/O,主要作为Node.js的多平台支持库。
[libuv](http://libuv.org/)是一个跨平台库,基于事件驱动来实现异步I/O,主要作为Node.js的多平台支持库。
## 支持的能力
libuv实现了跨平台的基于事件驱动的异步I/O。
[libuv](http://libuv.org/)实现了跨平台的基于事件驱动的异步I/O。
支持标准库接口。
## 接口列表
[libuv支持的API文档](http://docs.libuv.org/en/v1.x/api.html)
支持标准库接口。
\ No newline at end of file
......@@ -58,7 +58,7 @@ OsMuxInit
## 注释
一般的,尽量通过清晰的软件架构,良好的符号命名来提高代码可读性;然后在需要的时候,才辅以注释说明。
一般的,尽量通过清晰的软件架构,良好的符号命名来提高代码可读性;在需要的时候,辅以注释说明。
注释是为了帮助阅读者快速读懂代码,所以要从读者的角度出发,按需注释。
......
......@@ -84,7 +84,7 @@ typedef struct tagEvent {
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> - 进行事件读写操作时,事件的第25位为保留位,不可以进行位设置。
> - 进行事件读写操作时,事件的第25bit(`0x02U << 24`)为保留bit位,不可以进行位设置。
>
> - 对同一事件反复写入,算作一次写入。
......
......@@ -7,7 +7,7 @@
任务能够从队列里面读取消息,当队列中的消息为空时,挂起读取任务;当队列中有新消息时,挂起的读取任务被唤醒并处理新消息。任务也能够往队列里写入消息,当队列已经写满消息时,挂起写入任务;当队列中有空闲消息节点时,挂起的写入任务被唤醒并写入消息。
可以通过调整读队列和写队列的超时时间来调整读写接口的阻塞模式,如果将读队列和写队列的超时时间设置为0,就不会挂起任务,接口会直接返回,这就是非阻塞模式。反之,如果将队列和写队列的超时时间设置为大于0的时间,就会以阻塞模式运行。
可以通过调整读队列和写队列的超时时间来调整读写接口的阻塞模式,如果将读队列和写队列的超时时间设置为0,就不会挂起任务,接口会直接返回,这就是非阻塞模式。反之,如果将队列和写队列的超时时间设置为大于0的时间,就会以阻塞模式运行。
消息队列提供了异步处理机制,允许将一个消息放入队列,但不立即处理。同时队列还有缓冲消息的作用,可以使用队列实现任务异步通信,队列具有如下特性:
......
......@@ -14,9 +14,9 @@
| **功能分类** | **接口描述** |
| -------- | -------- |
| 置1/清0标志位 | -&nbsp;LOS_BitmapSet:对状态字的某一标志位进行置1操作<br/>-&nbsp;LOS_BitmapClr:对状态字的某一标志位进行清0操作 |
| 获取标志位为1的bit位 | -&nbsp;LOS_HighBitGet:获取状态字中为1的最高位<br/>-&nbsp;LOS_LowBitGet:获取状态字中为1的最低位 |
| 连续bit位操作 | -&nbsp;LOS_BitmapSetNBits:对状态字的连续标志位进行置1操作<br/>-&nbsp;LOS_BitmapClrNBits:对状态字的连续标志位进行清0操作<br/>-&nbsp;LOS_BitmapFfz:获取从最低有效位开始的第一个0的bit位 |
| 置1/清0标志位 | -&nbsp;LOS_BitmapSet:对状态字的某一标志位进行置1操作<br/>-&nbsp;LOS_BitmapClr:对状态字的某一标志位进行清0操作 |
| 获取标志位为1的bit位 | -&nbsp;LOS_HighBitGet:获取状态字中为1的最高位<br/>-&nbsp;LOS_LowBitGet:获取状态字中为1的最低位 |
| 连续bit位操作 | -&nbsp;LOS_BitmapSetNBits:对状态字的连续标志位进行置1操作<br/>-&nbsp;LOS_BitmapClrNBits:对状态字的连续标志位进行清0操作<br/>-&nbsp;LOS_BitmapFfz:获取从最低有效位开始的第一个0的bit位 |
## 编程实例
......@@ -34,7 +34,10 @@
4. 获取标志位为1的最低bit位。
### 编程示例
本演示代码在./kernel/liteos_a/testsuites/kernel/src/osTest.c中编译验证,在TestTaskEntry中调用验证入口函数BitSample。
```
#include "los_bitmap.h"
#include "los_printf.h"
......
......@@ -17,10 +17,10 @@
| 增加节点 | -&nbsp;LOS_ListAdd:将指定节点插入到双向链表头端<br/>-&nbsp;LOS_ListHeadInsert:将指定节点插入到双向链表头端,同LOS_ListAdd<br/>-&nbsp;LOS_ListTailInsert:将指定节点插入到双向链表尾端 |
| 增加链表 | -&nbsp;LOS_ListAddList:将指定链表的头端插入到双向链表头端<br/>-&nbsp;LOS_ListHeadInsertList:将指定链表的头端插入到双向链表头端<br/>-&nbsp;LOS_ListTailInsertList:将指定链表的尾端插入到双向链表头端 |
| 删除节点 | -&nbsp;LOS_ListDelete:将指定节点从链表中删除<br/>-&nbsp;LOS_ListDelInit:将指定节点从链表中删除,并使用该节点初始化链表 |
| 判断双向链表 | -&nbsp;LOS_ListEmpty:判断链表是否为空<br/>-&nbsp;LOS_DL_LIST_IS_END:判断指定链表节点是否为链表尾端LOS_DL_LIST_IS_ON_QUEUE:判断链表节点是否在双向链表里 |
| 判断双向链表 | -&nbsp;LOS_ListEmpty:判断链表是否为空<br/>-&nbsp;LOS_DL_LIST_IS_END:判断指定链表节点是否为链表尾端<br/>-&nbsp;LOS_DL_LIST_IS_ON_QUEUE:判断链表节点是否在双向链表里 |
| 获取结构体信息 | -&nbsp;LOS_OFF_SET_OF:获取指定结构体内的成员相对于结构体起始地址的偏移量<br/>-&nbsp;LOS_DL_LIST_ENTRY:获取双向链表中第一个链表节点所在的结构体地址,接口的第一个入参表示的是链表中的头节点,第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称<br/>-&nbsp;LOS_ListPeekHeadType:获取双向链表中第一个链表节点所在的结构体地址,接口的第一个入参表示的是链表中的头节点,第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称。如果链表为空,返回NULL。<br/>-&nbsp;LOS_ListRemoveHeadType:获取双向链表中第一个链表节点所在的结构体地址,并把第一个链表节点从链表中删除。接口的第一个入参表示的是链表中的头节点,第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称。如果链表为空,返回NULL。<br/>-&nbsp;LOS_ListNextType:获取双向链表中指定链表节点的下一个节点所在的结构体地址。接口的第一个入参表示的是链表中的头节点,第二个入参是指定的链表节点,第三个入参是要获取的结构体名称,第四个入参是链表在该结构体中的名称。如果链表节点下一个为链表头结点为空,返回NULL。|
| 遍历双向链表 | -&nbsp;LOS_DL_LIST_FOR_EACH:遍历双向链表<br/>-&nbsp;LOS_DL_LIST_FOR_EACH_SAFE:遍历双向链表,并存储当前节点的后继节点用于安全校验 |
| 遍历包含双向链表的结构体 | -&nbsp;LOS_DL_LIST_FOR_EACH_ENTRY:遍历指定双向链表,获取包含该链表节点的结构体地址<br/>-&nbsp;LOS_DL_LIST_FOR_EACH_ENTRY_SAFE:遍历指定双向链表,获取包含该链表节点的结构体地址,并存储包含当前节点的后继节点的结构体地址 |
| 遍历双向链表 | -&nbsp;LOS_DL_LIST_FOR_EACH:遍历双向链表<br/>-&nbsp;LOS_DL_LIST_FOR_EACH_SAFE:遍历双向链表,并存储当前节点的后继节点用于安全校验 |
| 遍历包含双向链表的结构体 | -&nbsp;LOS_DL_LIST_FOR_EACH_ENTRY:遍历指定双向链表,获取包含该链表节点的结构体地址<br/>-&nbsp;LOS_DL_LIST_FOR_EACH_ENTRY_SAFE:遍历指定双向链表,获取包含该链表节点的结构体地址,并存储包含当前节点的后继节点的结构体地址 |
## 开发流程
......@@ -48,10 +48,10 @@
> - 如果链表节点的内存是动态申请的,删除节点时,要注意释放内存。
**编程实例**
## 编程实例
**实例描述**
### 实例描述
本实例实现如下功能:
......@@ -64,7 +64,11 @@
4. 测试操作是否成功。
### 编程示例
本演示代码在./kernel/liteos_a/testsuites/kernel/src/osTest.c中编译验证,在TestTaskEntry中调用验证入口函数ListSample
示例代码如下:
```
#include "stdio.h"
......
......@@ -15,11 +15,19 @@ musl libc库支持POSIX标准,涉及的系统调用相关接口由OpenHarmony
标准库支持接口的详细情况请参考C库的API文档,其中也涵盖了与POSIX标准之间的差异说明。
## 操作实例
### 编程实例
#### 实例描述
在本示例中,主线程创建了THREAD_NUM个子线程,每个子线程启动后等待被主线程唤醒,主线程成功唤醒所有子线程后,子线程继续执行直至生命周期结束,同时主线程通过pthread_join方法等待所有线程执行结束。
#### 编程示例
本演示代码在./kernel/liteos_a/testsuites/kernel/src/osTest.c中编译验证,在TestTaskEntry中调用验证入口函数testcase 或新建文件由主函数调用
示例代码如下:
```
#include <stdio.h>
#include <unistd.h>
......
......@@ -116,9 +116,10 @@ typedef struct {
### 编程示例
本演示代码在./kernel/liteos_a/testsuites/kernel/src/osTest.c中编译验证,在TestTaskEntry中调用验证入口函数ExampleSem。
示例代码如下:
```
#include "los_sem.h"
#include "securec.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册