提交 9df1f727 编写于 作者: R RayShih

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

......@@ -20,6 +20,7 @@
- [Data Management](database/Readme-EN.md)
- [Device](device/Readme-EN.md)
- [DFX](dfx/Readme-EN.md)
- [Window Manager](windowmanager/Readme-EN.md)
- Tools
- [DevEco Studio \(OpenHarmony\) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md)
- Hands-On Tutorials
......
# Device Usage Statistics
- [Device Usage Statistics Overview](device-usage-statistics-overview.md)
- [Device Usage Statistics Development](device-usage-statistics-dev-guide.md)
## Device Usage Statistics Development
## When to Use
With device usage statistics APIs, you can have a better understanding of the application, notification, and system usage. For example, in application usage statistics, you can query the application usage, event log, and bundle group.
The application records (usage history statistics and event records) cached by components are updated to the database for persistent storage within 30 minutes after an event is reported.
## Available APIs
Import the **stats** package to implement registration:
```js
import stats from '@ohos.bundleState';
```
**Table 1** Major APIs for device usage statistics
| API| Description|
| -------- | -------- |
| function queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveState>>): void | Queries events of all applications based on the specified start time and end time.|
| function queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback<BundleActiveInfoResponse>): void | Queries the application usage duration statistics based on the specified start time and end time.|
| function queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveState>>): void | Queries events of this application based on the specified start time and end time.|
| function queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStateInfo>>): void | Queries the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually).|
| function queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void | Queries the priority group of the current invoker application.|
| function isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void | Checks whether the application specified by **bundleName** is in the idle state. |
## How to Develop
1. Configure the device usage statistics permission in the **config.json** file.
```json
"module": {
"package": "com.example.deviceUsageStatistics",
...,
"reqPermissions": [
{
"name": "ohos.permission.BUNDLE_ACTIVE_INFO"
}
]
}
```
2. Query events of all applications based on the specified start time and end time. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured in the **config.json** file.
```js
import stats from '@ohos.bundleState'
// Use a promise to return the result.
stats.queryBundleActiveStates(0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code);
});
// Use an asynchronous callback to return the result.
stats.queryBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i]));
}
} else {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
}
});
```
3. Query the application usage duration statistics based on the specified start time and end time. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured in the **config.json** file.
```js
import stats from '@ohos.bundleState'
// Use a promise to return the result.
stats.queryBundleStateInfos(0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1;
for(let key in res){
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
i++;
}
}).catch( err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code);
});
// Use an asynchronous callback to return the result.
stats.queryBundleStateInfos(0, 20000000000000, (err, res) => {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.');
let i = 1;
for(let key in res){
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key]));
i++;
}
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
}
});
```
4. Query events of this application based on the specified start time and end time. This requires no permission to be configured in the **config.json** file.
```js
import stats from '@ohos.bundleState'
// Use a promise to return the result.
stats.queryCurrentBundleActiveStates(0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code);
});
// Use an asynchronous callback to return the result.
stats.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i]));
}
} else {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
}
});
```
5. Query the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually). This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured in the **config.json** file.
```js
import stats from '@ohos.bundleState'
// Use a promise to return the result.
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i]));
}
}).catch( err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code);
});
// Use an asynchronous callback to return the result.
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => {
if(err.code == 0) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i]));
}
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
}
});
```
6. Query the priority group of the current invoker application. This requires no permission to be configured in the **config.json** file.
```js
import stats from '@ohos.bundleState'
// Use a promise to return the result.
stats.queryAppUsagePriorityGroup().then( res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code);
});
// Use an asynchronous callback to return the result.
stats.queryAppUsagePriorityGroup((err, res) => {
if(err.code === 0) {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} else {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code);
}
});
```
7. Check whether the application specified by **bundleName** is in the idle state. This requires no permission to be configured in the **config.json** file.
```js
import stats from '@ohos.bundleState'
// Use a promise to return the result.
stats.isIdleState("com.ohos.camera").then( res => {
console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
}).catch( err => {
console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code);
});
// Use an asynchronous callback to return the result.
stats.isIdleState("com.ohos.camera", (err, res) => {
if(err.code === 0) {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
} else {
console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code);
}
});
```
# Device Usage Statistics Overview
With device usage statistics APIs, you can have a better understanding of the application, notification, and system usage. In application usage statistics, you can query the application usage, event log, and bundle group. The application records (usage history statistics and event records) cached by components are updated to the database for persistent storage within 30 minutes after an event is reported.
## Introduction
Currently you can have access to statistics on the application usage, and notification and system usage statistics feature will be available for use in later versions.
- **The application usage statistics is updated**:
>1. Every 30 minutes
>2. Upon system time change
>3. Upon start of a new day
- **The application usage statistics can include the following**:
>1. Events of all applications based on the specified start time and end time
>2. Application usage duration statistics based on the specified start time and end time
>3. Events of the current application based on the specified start time and end time
>4. Application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually)
>5. Priority group of the current invoker application
>6. Whether a specific application is in the idle state
### Required Permissions
- The **queryBundleActiveStates**, **queryBundleStateInfos**, and **queryBundleStateInfoByInterval** APIs used for device usage statistics are system APIs. Before calling these APIs, you need to apply for the **ohos.permission.BUNDLE_ACTIVE_INFO** permission.
- This permission is not required for calling **queryCurrentBundleActiveStates**, **queryAppUsagePriorityGroup**, and **isIdleState**, which are third-party APIs.
# Sensor Development
## When to Use
- Data provided by the compass sensor denotes the current orientation of the user device, which helps your application accurately navigate for the user.
- Data provided by the proximity sensor denotes the distance between the device and a visible object, which enables the device to automatically turn on or off its screen accordingly to prevent accidental touch on the screen.
- Data provided by the barometer sensor helps your application accurately determine the altitude of the device.
- Data provided by the ambient light sensor helps your device automatically adjust its backlight.
- Data provided by the Hall effect sensor implements the smart cover mode of your device.
- Data provided by the heart rate sensor helps your application track the health of a user.
- Data provided by the pedometer sensor helps your application obtain the number steps a user has walked.
- Data provided by the wear detection sensor helps your application detect whether a user is wearing a wearable device.
## Available APIs
| Module | API | Description |
| -------- | -------- | -------- |
| ohos.sensor | sensor.on(sensorType,callback:AsyncCallback&lt;Response&gt;):void | Subscribes to data changes of a type of sensor. |
| ohos.sensor | sensor.once(sensorType,callback:AsyncCallback&lt;Response&gt;):void | Subscribes to only one data change of a type of sensor. |
| ohos.sensor | sensor.off(sensorType,callback:AsyncCallback&lt;void&gt;):void | Unsubscribes from sensor data changes. |
## How to Develop
1. To obtain data from a type of sensor, configure the request permissions in the **config.json** file.
```
"reqPermissions":[
{
"name":"ohos.permission.ACCELEROMETER",
"reason"":"",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
}
},
{
"name":"ohos.permission.GYROSCOPE",
"reason"":"",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
}
},
{
"name":"ohos.permission.ACTIVITY_MOTION",
"reason"":"ACTIVITY_MOTION_TEST",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
}
},
{
"name":"ohos.permission.READ_HEALTH_DATA",
"reason"":"HEALTH_DATA_TEST",
"usedScene":{
"ability": ["sensor.index.MainAbility",".MainAbility"],
"when":"inuse"
}
},
{
"name":"ohos.permission.VIBRATE",
"reason"":"",
"usedScene":{
"ability": [".MainAbility"],
"when":"inuse"
}
},
]
```
2. Subscribe to data changes of a type of sensor.
```
import sensor from "@ohos.sensor"
sensor.on(type:sensorType,function(error,data){
if (error) {// The call fails, and error.code and error.message are printed.
console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
return;
};
console.info("Subscription succeeded. data = "+ data);// The call is successful, and the obtained sensor data is printed.
}
);
```
The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**.
![en-us_image_0000001241693881](figures/en-us_image_0000001241693881.png)
3. Unsubscribe from sensor data changes.
```
import sensor from "@ohos.sensor"
sensor.off(type:sensorType,function(error) {
if (error) {// The unsubscription fails, and error.code and error.message are printed.
console.error("Failed to unsubscribe from acceleration sensor data. Error code: " + error.code + "; message: " + error.message);
return;
};
console.info("Succeeded in unsubscribing from acceleration sensor data.");// The unsubscription is successful, and the result is printed.
}
);
```
The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**.
![en-us_image_0000001196654004](figures/en-us_image_0000001196654004.png)
4. Subscribe to only one data change of a type of sensor.
```
import sensor from "@ohos.sensor"
sensor.once(tyep:sensorType,function(error, data) {
if (error) {// The call fails, and error.code and error.message are printed.
console.error("Failed to obtain data. Error code: " + error.code + "; message: " + error.message);
return;
};
console.info("Data obtained successfully. data="+data);// The call is successful, and the obtained sensor data is printed.
}
);
```
The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**.
![en-us_image_0000001241733907](figures/en-us_image_0000001241733907.png)
# Sensor Overview
Sensors in OpenHarmony are an abstraction of underlying hardware-based sensors. Your application can access the underlying sensors via OpenHarmony sensors. Using the APIs provided by OpenHarmony sensors, you can query sensors on your device, subscribe to sensor data, customize algorithms based on sensor data, and develop various sensor-based applications, such as compass, fitness and health, and games applications.
The sensors are classified into the following categories based on their functions: motion, environment, orientation, light, body, and other categories (such as Hall effect sensors). Each category includes different sensor types. A sensor type may be a single physical sensor or a composite of multiple physical sensors.
**Table1** Motion - ohos.sensor.agent.CategoryMotionAgent
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_ACCELEROMETER | Acceleration sensor | Measures the acceleration (including the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s<sup>2</sup>. | Detecting the motion status |
| SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED | Uncalibrated acceleration sensor | Measures the uncalibrated acceleration (including the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s<sup>2</sup>. | Measuring the acceleration bias estimation |
| SENSOR_TYPE_LINEAR_ACCELERATION | Linear acceleration sensor | Measures the linear acceleration (excluding the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s<sup>2</sup>. | Detecting the linear acceleration in each axis |
| SENSOR_TYPE_GRAVITY | Gravity sensor | Measures the gravity acceleration applied to a device on three physical axes (X, Y, and Z), in the unit of m/s<sup>2</sup>. | Measuring the gravity |
| SENSOR_TYPE_GYROSCOPE | Gyroscope sensor | Measures the rotation angular velocity of a device on three physical axes (X, Y, and Z), in the unit of rad/s. | Measuring the rotation angular velocity |
| SENSOR_TYPE_GYROSCOPE_UNCALIBRATED | Uncalibrated gyroscope sensor | Measures the uncalibrated rotation angular velocity of a device on three physical axes (X, Y, and Z), in the unit of rad/s. | Measuring the bias estimation of the rotation angular velocity |
| SENSOR_TYPE_SIGNIFICANT_MOTION | Significant motion sensor | Checks whether a device has a significant motion on three physical axes (X, Y, and Z). The value can be **0** (having no significant motion) or **1** (having a significant motion). | Detecting significant motions of a device |
| SENSOR_TYPE_DROP_DETECTION | Drop detection sensor | Detects the device drop status. The value can be **0** (the device is not dropped) or **1** (the device is dropped). | Detecting whether a device is dropped |
| SENSOR_TYPE_PEDOMETER_DETECTION | Pedometer detection sensor | Detects whether a user takes a step. The value can be **0** (the user does not take a step) or **1** (the user takes a step). | Detecting whether a user takes a step |
| SENSOR_TYPE_PEDOMETER | Pedometer sensor | Records the number of steps a user has walked. | Providing the number of steps a user has walked |
**Table2** Environment - ohos.sensor.agent.CategoryOrientationAgent
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_AMBIENT_TEMPERATURE | Ambient temperature sensor. | Measures the ambient temperature, in the unit of degree Celsius (°C). | Measuring the ambient temperature |
| SENSOR_TYPE_MAGNETIC_FIELD | Magnetic field sensor | Measures the magnetic field on three physical axes (X, Y, and Z), in the unit of μT. | Creating a compass |
| SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED | Uncalibrated magnetic field sensor | Measures the uncalibrated magnetic field on three physical axes (X, Y, and Z), in the unit of μT. | Measuring the magnetic field bias estimation |
| SENSOR_TYPE_HUMIDITY | Humidity sensor | Measures the ambient relative humidity, in a percentage (%). | Monitoring the dew point, absolute humidity, and relative humidity |
| SENSOR_TYPE_BAROMETER | Barometer sensor | Measures the barometric pressure, in the unit of hPa or mbar. | Measuring the barometric pressure |
| SENSOR_TYPE_SAR | Specific Absorption Rate (SAR) sensor | Measures the SAR, in the unit of W/kg. | Measuring the SAR of electromagnetic waves for a device |
**Table3** Orientation - ohos.sensor.agent.CategoryOrientationAgent
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_6DOF | Degrees of Freedom (DoF) sensor | Measures the forward/backward, up/down, and left/right translational movement of a device on the three axes (X, Y, and Z) in the unit of m or mm as well as the roll, pitch, and yaw rotation angles on the three axes (X, Y, and Z) in the unit of rad. | Positioning an object by detecting its freedom of translational and rotational motions, for example, VR |
| SENSOR_TYPE_SCREEN_ROTATION | Screen rotation sensor | Checks the rotation status of the device screen. | Detecting whether the device screen is rotating |
| SENSOR_TYPE_DEVICE_ORIENTATION | Device orientation sensor | Measures the rotation angles of the device, in the unit of rad. | Measuring the angles that a device has rotated |
| SENSOR_TYPE_ORIENTATION | Orientation sensor | Measures the rotation angles of a device on three physical axes (X, Y, and Z), in the unit of rad. | Providing the three orientation angles of the screen |
| SENSOR_TYPE_ROTATION_VECTOR | Rotation vector sensor | Measures the rotation vector of a device. It is a composite sensor that generates data from the acceleration sensor, magnetic field sensor, and gyroscope sensor. | Detecting the orientation of a device in the East, North, Up (ENU) Cartesian coordinate system |
| SENSOR_TYPE_GAME_ROTATION_VECTOR<br/>SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR | Game rotation vector sensor<br/>Geomagnetic rotation vector sensor | Measures the game rotation vector of a device. It is a composite sensor that generates data from the acceleration sensor and gyroscope sensor.<br/>Measures the geomagnetic rotation vector of a device. It is a composite sensor that generates data from the acceleration sensor and magnetic field sensor. | Applied in games<br/>Measuring the geomagnetic rotation vector |
**Table4** Light - ohos.sensor.agent.CategoryLightAgent
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_PROXIMITY | Proximity sensor | Measures the distance between a visible object and the device screen. | Measuring the distance between a person and the device during a call |
| SENSOR_TYPE_TOF | Time of flight (ToF) sensor | Measures the time required for light to travel a distance in the medium. | Facial recognition |
| SENSOR_TYPE_AMBIENT_LIGHT | Ambient light sensor | Measures the ambient light intensity of a device, in the unit of lux. | Automatically adjusting the screen brightness and checking whether the screen is covered on the top |
| SENSOR_TYPE_COLOR_TEMPERATURE | Color temperature sensor | Measures the ambient color temperature. | Image processing on the device |
| SENSOR_TYPE_COLOR_RGB | RGB color sensor | Measures the ambient RGB color values. | Color detection implemented by the reflectance of RGB colors |
| SENSOR_TYPE_COLOR_XYZ | XYZ color sensor | Measures the ambient XYZ color values. | Identifying true-color spots to reproduce more natural colors |
**Table5** Body - ohos.sensor.agent.CategoryBodyAgent
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_HEART_RATE | Heart rate sensor | Measures the heart rate of a user. | Providing users' heart rate data |
| SENSOR_TYPE_WEAR_DETECTION | Wear detection sensor | Checks whether a user is wearing a wearable device. | Detecting wearables |
**Table6** Others
| Sensor Type | Sensor Name | Description | Usage |
| -------- | -------- | -------- | -------- |
| SENSOR_TYPE_HALL | Hall effect sensor | Detects a magnetic field around a device. | Smart cover mode of the device |
| SENSOR_TYPE_GRIP_DETECTOR | Grip detection sensor | Detects grip force applied on a device. | Detecting whether the device is gripped on its sides |
| SENSOR_TYPE_MAGNET_BRACKET | Magnet bracket sensor | Checks whether a device is magnetized. | Detecting an in-vehicle or indoor device |
| SENSOR_TYPE_PRESSURE_DETECTOR | Pressure detection sensor | Detects pressure force applied on a device. | Detecting pressure on the top of the device |
## How a Service Is Shared Using Huawei Share
The following modules work cooperatively to implement OpenHarmony sensors: Sensor API, Sensor Framework, Sensor Service, and HD_IDL.
**Figure1** Working principles for OpenHarmony sensors
![en-us_image_0000001226521897](figures/en-us_image_0000001226521897.png)
- Sensor API: provides APIs for performing basic operations on sensors, including querying the sensor list, subscribing to or unsubscribing from sensor data, and executing control commands. This module makes application development simpler.
- Sensor Framework: manages sensor data subscription, creates and destroys data channels, subscribes to or unsubscribes from sensor data, and implements communication with the Sensor Service module.
- Sensor Service: interacts with the HD_IDL module to receive, parse, and distribute data, manages foreground and background policies and sensors of a device, and controls sensor permissions.
- HD_IDL: selects proper policies based on the hardware first in first out (FIFO) and frequency, and adapts to different devices.
## Limitations and Constraints
To obtain data of the following sensors, you must claim the required permissions.
**Table7** Sensor data permission
| Sensor | Permission Name | Sensitivity | Permission Description |
| -------- | -------- | -------- | -------- |
| Acceleration sensor, uncalibrated acceleration sensor, and linear acceleration sensor | ohos.permission.ACCELEROMETER | system_grant | Allows your application to subscribe to data of these acceleration-related sensors in the motion category. |
| Gyroscope sensor and uncalibrated gyroscope sensor | ohos.permission.GYROSCOPE | system_grant | Allows your application to subscribe to data of these gyroscope-related sensors in the motion category. |
| Pedometer sensor | ohos.permission.ACTIVITY_MOTION | user_grant | Allows your application to subscribe to the motion status. |
| Heart rate sensor | ohos.permission.READ_HEALTH_DATA | user_grant | Allows your application to read health data. |
The APIs for subscribing to and unsubscribing from sensor data work in pairs. If you do not need sensor data, call the unsubscription API to stop sensor data reporting.
# Image Development
## When to Use
You can use image development APIs to decode images into pixel maps and encode the pixel maps into a supported format.
## Available APIs
For details about the APIs, see [js-apis-image.md](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-image.md).
## How to Develop
### Full-Process Scenario
The full process includes creating an instance, reading image information, reading and writing pixel maps, updating data, packaging pixels, and releasing resources.
```js
const Color = new ArrayBuffer(96); // Create a buffer to store image pixel data.
let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } } // Image pixel data.
// Create a PixelMap object.
const Color = new ArrayBuffer(96);
let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 2, width: 3 } }
image.createPixelMap(Color, opts, pixelmap => {
expect(pixelmap !== null).assertTrue();
console.info('TC_001-1 success');
done();
})
// Read pixels.
pixelmap.readPixels(area,(data) => {
if(data !== null) {
var bufferArr = new Uint8Array(area.pixels);
var res = true;
for (var i = 0; i < bufferArr.length; i++) {
console.info('TC_021-1 buffer ' + bufferArr[i]);
if(res) {
if(bufferArr[i] == 0) {
res = false;
console.info('TC_021-1 Success');
expect(true).assertTrue();
done();
break;
}
}
}
// Store pixels.
const readBuffer = new ArrayBuffer(96);
pixelmap.readPixelsToBuffer(readBuffer,() => {
var bufferArr = new Uint8Array(readBuffer);
var res = true;
for (var i = 0; i < bufferArr.length; i++) {
if(res) {
if (bufferArr[i] !== 0) {
res = false;
console.info('TC_020-1 Success');
expect(true).assertTrue();
done();
break;
}
}
}
// Write pixels.
pixelmap.writePixels(area,() => {
const readArea = { pixels: new ArrayBuffer(20), offset: 0, stride: 8, region: { size: { height: 1, width: 2 }, x: 0, y: 0 }}
pixelmap.readPixels(readArea,() => {
var readArr = new Uint8Array(readArea.pixels);
var res = true;
for (var i = 0; i < readArr.length; i++) {
if(res) {
if (readArr[i] !== 0) {
res = false;
console.info('TC_022-1 Success');
expect(true).assertTrue();
done();
break;
}
}
}
// Write pixels to the buffer.
pixelmap.writeBufferToPixels(writeColor).then(() => {
const readBuffer = new ArrayBuffer(96);
pixelmap.readPixelsToBuffer(readBuffer).then (() => {
var bufferArr = new Uint8Array(readBuffer);
var res = true;
for (var i = 0; i < bufferArr.length; i++) {
if(res) {
if (bufferArr[i] !== i) {
res = false;
console.info('TC_023 Success');
expect(true).assertTrue()
done();
break;
}
}
}
// Obtain image information.
pixelmap.getImageInfo( imageInfo => {
if (imageInfo !== null) {
console.info('TC_024-1 imageInfo is ready');
expect(imageInfo.size.height == 4).assertTrue();
expect(imageInfo.size.width == 6).assertTrue();
expect(imageInfo.pixelFormat == 4).assertTrue();
done();
}
})
// Release the PixelMap object.
pixelmap.release(()=>{
expect(true).assertTrue();
console.log('TC_027-1 suc');
done();
})
// Create an image source (uri).
const imageSourceApi = image.createImageSource(path);//'/data/local/tmp/test.jpg'
// Create an image source (fd).
const imageSourceApi = image.createImageSource(29);
// Create an image source (data).
const data = new ArrayBuffer(96);
const imageSourceApi = image.createImageSource(data);
// Release the image source.
imageSourceApi.release(() => {
console.info('TC_044-1 Success');
})
// Encode the image.
const imagePackerApi = image.createImagePacker();
imagePackerApi.packing(imageSourceApi, packOpts, data => {
console.info('TC_062-1 finished');
expect(data !== null).assertTrue();
done();
})
// Release the ImagePacker object.
imagePackerApi.release();
```
### Decoding Scenario
```js
/data/local/tmp/test.jpg // Set the path for creating an image source.
// Create an image source using a path.
const imageSourceApi = image.createImageSource(path);//'/data/local/tmp/test.jpg'
// Set parameters.
let decodingOptions = {
sampleSize:1, // Sampling size of the thumbnail.
editable: true, // Whether the image can be edited.
desiredSize:{ width:1, height:2}, // Desired output size of the image.
rotateDegrees:10, // Rotation angle of the image.
desiredPixelFormat:2, // Decoded pixel format.
desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 }, // Region of the image to decode.
index:0// Image sequence number.
};
// Create a pixel map in callback mode.
imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
console.info('TC_050 createPixelMap ');
expect(pixelmap !== null ).assertTrue();
done();
})
}
// Create a pixel map in promise mode.
imageSourceApi.createPixelMap().then(pixelmap => {
console.info('TC_050-11 createPixelMap ');
expect(pixelmap !== null ).assertTrue();
done();
})
// Capture error information when an exception occurs during function invoking.
catch(error => {
console.log('TC_050-11 error: ' + error);
expect().assertFail();
done();
})
// Obtain the number of bytes in each line of pixels.
pixelmap.getBytesNumberPerRow( num => {
console.info('TC_025-1 num is ' + num);
expect(num == expectNum).assertTrue();
done();
})
// Obtain the total number of pixel bytes.
pixelmap.getPixelBytesNumber(num => {
console.info('TC_026-1 num is ' + num);
expect(num == expectNum).assertTrue();
done();
})
// Obtain the pixel map information.
pixelmap.getImageInfo( imageInfo => {})
// Print the failure information.
console.info('TC_024-1 imageInfo is empty');
expect(false).assertTrue()
// Release the PixelMap object.
pixelmap.release(()=>{
expect(true).assertTrue();
console.log('TC_027-1 suc');
done();
})
// Capture release failure information.
catch(error => {
console.log('TC_027-1 error: ' + error);
expect().assertFail();
done();
})
```
### Encoding Scenario
```js
/data/local/tmp/test.png // Set the path for creating an image source.
// Set the image source.
const imageSourceApi = image.createImageSource(path);//'/data/local/tmp/test.png'
// Print the error message if the image source fails to be created.
if (imageSourceApi == null) {
console.info('TC_062 create image source failed');
expect(false).assertTrue();
done();
}
// Create an image packer if the image source is successfully created.
const imagePackerApi = image.createImagePacker();
// Print the error information if the image packer fails to be created.
if (imagePackerApi == null) {
console.info('TC_062 create image packer failed');
expect(false).assertTrue();
done();
}
// Set encoding parameters if the image packer is successfully created.
let packOpts = { format:["image/jpeg"], // The supported encoding format is jpg.
quality:98 }// Image quality, which ranges from 0 to 100.
// Encode the image.
imagePackerApi.packing(imageSourceApi, packOpts)
.then( data => {
console.info('TC_062 finished');
expect(data !== null).assertTrue();
done();
})
// Release the image packer after the encoding is complete.
imagePackerApi.release();
// Obtain the image source information.
imageSourceApi.getImageInfo(imageInfo => {
console.info('TC_045 imageInfo');
expect(imageInfo !== null).assertTrue();
done();
})
// Update incremental data.
imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data )=> {})
```
......@@ -79,6 +79,7 @@
- [WebGL](js-apis-webgl.md)
- [WebGL2](js-apis-webgl2.md)
- [Screenshot](js-apis-screenshot.md)
- [Accessibility](js-apis-accessibility.md)
- DFX
- [HiAppEvent](js-apis-hiappevent.md)
- [Performance Tracing](js-apis-hitracemeter.md)
......@@ -109,4 +110,6 @@
- [Nonlinear Container TreeSet](js-apis-treeset.md)
- [Nonlinear Container LightWeightMap](js-apis-lightweightmap.md)
- [Nonlinear Container LightWeightSet](js-apis-lightweightset.md)
- Custom Management
- [Configuration Policy](js-apis-config-policy.md)
# DataUriUtils Module
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
......@@ -12,15 +15,17 @@ getId(uri: string): number
Obtains the ID attached to the end of a given URI.
**Parameters**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| uri | string | Yes| URI object from which the ID is to be obtained.|
| uri | string | Yes | URI object from which the ID is to be obtained.|
**Return value**
| Type| Description|
| Type | Description |
| ------ | ------------------------ |
| number | ID obtained from the URI object.|
......@@ -38,16 +43,18 @@ attachId(uri: string, id: number): string
Attaches an ID to the end of a given URI.
**Parameters**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| uri | string | Yes| URI object to which an ID is to be attached.|
| id | number | Yes| ID to be attached.|
| uri | string | Yes | URI object to which an ID is to be attached.|
| id | number | Yes | ID to be attached. |
**Return value**
| Type| Description|
| Type | Description |
| ------ | --------------------- |
| string | URI object with the ID attached.|
......@@ -69,14 +76,17 @@ deleteId(uri: string): string
Deletes the ID from the end of a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------------------- |
| uri | string | Yes| URI object from which the ID is to be deleted.|
| uri | string | Yes | URI object from which the ID is to be deleted.|
**Return value**
| Type| Description|
| Type | Description |
| ------ | ------------------- |
| string | URI object with the ID deleted.|
......@@ -94,15 +104,18 @@ updateId(uri: string, id: number): string
Updates the ID in a given URI.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ------------------- |
| uri | string | Yes| URI object to be updated.|
| id | number | Yes| New ID.|
| uri | string | Yes | URI object to be updated.|
| id | number | Yes | New ID. |
**Return value**
| Type| Description|
| Type | Description |
| ------ | --------------- |
| string | URI object with the new ID.|
......
......@@ -14,7 +14,7 @@ Before using the **AbilityContext** module, you must define a child class that i
```
```js
import Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
......@@ -28,28 +28,28 @@ class MainAbility extends Ability {
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| abilityInfo | AbilityInfo | Yes| No| Ability information.|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.|
| abilityInfo | AbilityInfo | Yes| No| Ability information.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
## startAbility
## AbilityContext.startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This method uses a callback to return the result.
Starts an ability. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example
```
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
......@@ -61,26 +61,25 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbility
## AbilityContext.startAbility
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void
Starts an ability. This method uses a callback to return the result.
Starts an ability. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want) | Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example
**Example**
```
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
......@@ -95,29 +94,30 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbility
## AbilityContext.startAbility
startAbility(want: Want, options: StartOptions): Promise&lt;void&gt;;
startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
Starts an ability. This method uses a promise to return the result.
Starts an ability. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
| options | StartOptions | No| Parameters used for starting the ability.|
**Return value**
- Return value
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
- Example
```
**Example**
```js
var want = {
"deviceId": "",
"bundleName": "com.extreme.test",
......@@ -135,25 +135,25 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbilityForResult
## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void;
Starts an ability. This method uses a callback to return the execution result when the ability is terminated.
Starts an ability. This API uses a callback to return the execution result when the ability is terminated.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
- Example
```
**Example**
```js
this.context.startAbilityForResult(
{bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"},
(error, result) => {
......@@ -163,17 +163,16 @@ SystemCapability.Ability.AbilityRuntime.Core
);
```
## startAbilityForResult
## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void;
Starts an ability. This method uses a callback to return the execution result when the ability is terminated.
Starts an ability. This API uses a callback to return the execution result when the ability is terminated.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want |[Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
......@@ -181,8 +180,9 @@ SystemCapability.Ability.AbilityRuntime.Core
| callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
- Example
```
**Example**
```js
var options = {
windowMode: 0,
};
......@@ -196,30 +196,31 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbilityForResult
## AbilityContext.startAbilityForResult
startAbilityForResult(want: Want, options: StartOptions): Promise&lt;AbilityResult&gt;;
startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityResult&gt;;
Starts an ability. This method uses a promise to return the execution result when the ability is terminated.
Starts an ability. This API uses a promise to return the execution result when the ability is terminated.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the **Want** used for starting an ability.|
| options | StartOptions | Yes| Parameters used for starting the ability.|
| options | StartOptions | No| Parameters used for starting the ability.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Promise used to return the result.|
- Example
```
**Example**
```js
var options = {
windowMode: 0,
};
......@@ -231,46 +232,46 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## terminateSelf
## AbilityContext.terminateSelf
terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This method uses a callback to return the result.
Terminates this ability. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
- Example
```
**Example**
```js
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err));
});
```
## terminateSelf
## AbilityContext.terminateSelf
terminateSelf(): Promise&lt;void&gt;;
Terminates this ability. This method uses a promise to return the result.
Terminates this ability. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Return value**
- Return value
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example
```
**Example**
```js
this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
......@@ -279,24 +280,24 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## terminateSelfWithResult
## AbilityContext.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void;
Terminates this ability. This method uses a callback to return the information to the caller of **startAbilityForResult**.
Terminates this ability. This API uses a callback to return the information to the caller of **startAbilityForResult**.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example
```
**Example**
```js
this.context.terminateSelfWithResult(
{
want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
......@@ -308,28 +309,29 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## terminateSelfWithResult
## AbilityContext.terminateSelfWithResult
terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
Terminates this ability. This method uses a promise to return information to the caller of **startAbilityForResult**.
Terminates this ability. This API uses a promise to return information to the caller of **startAbilityForResult**.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
- Example
```
**Example**
```js
this.context.terminateSelfWithResult(
{
want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
......@@ -341,29 +343,29 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## startAbilityByCall
## AbilityContext.startAbilityByCall
startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
Obtains the caller interface of the specified ability, and if the specified ability is not started, starts the ability in the background.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.|
- Return value
| Type| Description|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;&gt; | Promise used to return the caller object to communicate with.|
| Promise&lt;Caller&gt; | Promise used to return the caller object to communicate with.|
- Example
**Example**
```
```js
import Ability from '@ohos.application.Ability';
var caller;
export default class MainAbility extends Ability {
......@@ -383,23 +385,22 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## requestPermissionsFromUser
## AbilityContext.requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void;
Requests permissions from the user by displaying a pop-up window. This method uses a callback to return the result.
Requests permissions from the user by displaying a pop-up window. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.|
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.|
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
- Example
**Example**
```
this.context.requestPermissionsFromUser(permissions,(result) => {
......@@ -408,27 +409,27 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## requestPermissionsFromUser
## AbilityContext.requestPermissionsFromUser
requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;PermissionRequestResult&gt;;
Requests permissions from the user by displaying a pop-up window. This method uses a promise to return the result.
Requests permissions from the user by displaying a pop-up window. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| Permissions to request.|
| permissions | Array&lt;string&gt; | Yes| Permissions to request.|
**Return value**
- Return value
| Type| Description|
| Type| Description|
| -------- | -------- |
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the method is successfully called.|
| Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example
**Example**
```
this.context.requestPermissionsFromUser(permissions).then((data) => {
......@@ -439,54 +440,53 @@ SystemCapability.Ability.AbilityRuntime.Core
```
## setMissionLabel
## AbilityContext.setMissionLabel
setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;
Sets the label of the ability displayed in the task. This method uses a callback to return the result.
Sets the label of the ability displayed in the task. This API uses a callback to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the method is successfully called.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.|
- Example
**Example**
```
```js
this.context.setMissionLabel("test",(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringfy(result));
});
```
## setMissionLabel
## AbilityContext.setMissionLabel
setMissionLabel(label: string): Promise&lt;void&gt;
Sets the label of the ability displayed in the task. This method uses a promise to return the result.
Sets the label of the ability displayed in the task. This API uses a promise to return the result.
**System capabilities**
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| label | string | Yes| Label of the ability to set.|
- Return value
| Type| Description|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result indicating whether the method is successfully called.|
| Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.|
- Example
**Example**
```
```js
this.context.setMissionLabel("test").then((data) => {
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
......
......@@ -10,38 +10,39 @@ Provides ability running information.
## Usage
The ability running information is obtained by using the **getAbilityRunningInfos** method in **abilityManager**.
The ability running information is obtained by using the **getAbilityRunningInfos** API in **abilityManager**.
```
```js
import abilitymanager from '@ohos.application.abilityManager';
abilitymanager.getAbilityRunningInfos((err,data) => {
console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
```
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| ability | ElementName | Yes| No| Information that matches an ability.|
| ability | ElementName | Yes| No| Information that matches an ability. |
| pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID.|
| processName | string | Yes| No| Process name.|
| startTime | number | Yes| No| Ability start time.|
| abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state.|
| uid | number | Yes| No| User ID. |
| processName | string | Yes| No| Process name. |
| startTime | number | Yes| No| Ability start time. |
| abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | Yes| No| Ability state. |
## abilityManager.AbilityState
Enumerates the ability states.
| Name| Value| Description|
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Value| Description|
| -------- | -------- | -------- |
| INITIAL | 0 | The ability is in the initial state.|
| FOREGROUND | 9 | The ability is in the foreground state.|
| BACKGROUND | 10 | The ability is in the background state.|
| FOREGROUNDING | 11 | The ability is in the foregrounding state.|
| BACKGROUNDING | 12 | The ability is in the backgrounding state.|
| FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state. |
| FOREGROUNDING | 11 | The ability is in the foregrounding state. |
| BACKGROUNDING | 12 | The ability is in the backgrounding state. |
......@@ -14,7 +14,7 @@ The ability stage context is obtained through an **AbilityStage** instance.
```
```js
import AbilityStage from '@ohos.application.AbilityStage';
class MyAbilityStage extends AbilityStage {
onCreate() {
......@@ -25,8 +25,9 @@ class MyAbilityStage extends AbilityStage {
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| currentHapModuleInfo | HapModuleInfo | Yes| No| **ModuleInfo** object corresponding to the **AbilityStage**.|
| config | [Configuration](js-apis-configuration.md) | Yes| No| Configuration for the environment where the application is running.|
# MissionInfo
> **NOTE**
> The initial APIs of this module are supported since API 8.
Provides mission information of an ability.
## Modules to Import
Import **Want** before use.
```
import Want from "../@ohos.application.Want";
```
## MissionInfo
Describes the mission information.
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| missionId | number | Yes| Yes| Mission ID.|
| runningState | number | Yes| Yes| Running state of the mission.|
| lockedState | boolean | Yes| Yes| Locked state of the mission.|
| timestamp | string | Yes| Yes| Latest time when the mission was created or updated.|
| want | [Want](js-apis-featureAbility.md#want) | Yes| Yes| **Want** information of the mission.|
| label | string | Yes| Yes| Label of the mission.|
| iconPath | string | Yes| Yes| Path of the mission icon.|
| continuable | boolean | Yes| Yes| Whether the mission is continuable.|
# MissionSnapshot
> **NOTE**
> The initial APIs of this module are supported since API 8.
Provides snapshot of a mission.
## Modules to Import
Import ElementName and image before use.
```
import { ElementName } from '../bundle/elementName';
import { image } from '../@ohos.multimedia.image';
```
## MissionSnapshot
Describes the mission snapshot.
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| ability | ElementName | Yes| Yes| Information that matches an ability.|
| snapshot | [image.PixelMap](js-apis-image.md) | Yes| Yes| Snapshot of the mission.|
......@@ -4,26 +4,29 @@
> The initial APIs of this module are supported since API 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Runtime class for HAP files. It provides methods to notify you when a HAP file starts loading. You can then initialize the HAP file, for example, pre-load resources and create threads.
Runtime class for HAP files. It provides APIs to notify you when a HAP file starts loading. You can then initialize the HAP file, for example, pre-load resources and create threads.
## Modules to Import
```
```js
import AbilityStage from '@ohos.application.AbilityStage';
```
## onCreate
## AbilityStage.onCreate
onCreate(): void
Called when the application is created.
- Example
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Example**
```
```js
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called")
......@@ -32,25 +35,29 @@ Called when the application is created.
```
## onAcceptWant
## AbilityStage.onAcceptWant
onAcceptWant(want: Want): string;
Called when a specified ability is started.
- Parameters
| Name| Type| Mandatory| Description|
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-featureAbility.md#Want)| Yes| Information about the ability to start, such as the ability name and bundle name.|
- Return value
| Type| Description|
**Return value**
| Type| Description|
| -------- | -------- |
| string | Returns an ability ID. If this ability has been started, no new instance is created and the ability is placed at the top of the stack. Otherwise, a new instance is created and started.|
- Example
**Example**
```
```js
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
......@@ -60,23 +67,33 @@ Called when a specified ability is started.
```
## onConfigurationUpdated
## AbilityStage.onConfigurationUpdated
onConfigurationUpdated(config: Configuration): void;
Called when the global configuration is updated.
- Parameters
| Name| Type| Mandatory| Description|
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-configuration.md) | Yes| Callback invoked when the global configuration is updated. The global configuration indicates the configuration of the environment where the application is running and includes the language and color mode.|
- Example
**Example**
```
```js
class MyAbilityStage extends AbilityStage {
onConfigurationUpdated(config) {
console.log('onConfigurationUpdated, language:' + config.language);
}
}
```
## AbilityStage.context
Describes the configuration information about the context.
| Name | Type | Description |
| ----------- | --------------------------- | ------------------------------------------------------------ |
| context | [AbilityStageContext](js-apis-featureAbility.md) | Called when initialization is performed during ability startup.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core|
......@@ -14,6 +14,7 @@ You must extend **AbilityContext** to implement this module.
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
......@@ -29,44 +30,51 @@ You must extend **AbilityContext** to implement this module.
| eventHub | [EventHub](js-apis-eventhub.md) | Yes| No| Event hub information.|
## createBundleContext
## Context.createBundleContext
createBundleContext(bundleName: string): Context;
Creates an application context.
- **Parameters**
| Name| Type| Mandatory| Description|
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Application bundle name.|
- Return value
| Type| Description|
**Return value**
| Type| Description|
| -------- | -------- |
| Context | Context of the application created.|
- Example
**Example**
```
```js
let test = "com.example.test";
let context = this.context.createBundleContext(test);
```
## getApplicationContext
## Context.getApplicationContext
getApplicationContext(): Context;
Obtains the context of this application.
- Return value
| Type| Description|
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| Context | Context obtained.|
- Example
**Example**
```
```js
// This part is mandatory.
let context = this.context.getApplicationContext();
```
# appManager
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Implements application management.
......@@ -10,50 +10,159 @@ Implements application management.
## Modules to Import
```
```js
import app from '@ohos.application.appManager';
```
## isRunningInStabilityTest
## appManager.isRunningInStabilityTest<sup>8+</sup>
static isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether this application is undergoing a stability test. This API uses a callback to return the result.
Checks whether this application is undergoing a stability test. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result.|
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
- Example
**Example**
```
```js
import app from '@ohos.application.appManager';
app.isRunningInStabilityTest((err, flag) => {
console.log('startAbility result:' + JSON.stringfy(err);
}
console.log('startAbility result:' + JSON.stringfy(err));
})
```
## isRunningInStabilityTest
## appManager.isRunningInStabilityTest<sup>8+</sup>
static isRunningInStabilityTest(): Promise&lt;boolean&gt;
Checks whether this application is undergoing a stability test. This method uses a promise to return the result.
Checks whether this application is undergoing a stability test. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
- Return value
| Type| Description|
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
| Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
- Example
**Example**
```
```js
import app from '@ohos.application.appManager';
app.isRunningInStabilityTest().then((flag) => {
console.log('success:' + JSON.stringfy(flag));
)).catch((error) => {
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
```
## appManager.isRamConstrainedDevice
isRamConstrainedDevice(): Promise\<boolean>;
Checks whether this application is running in a RAM constrained device. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the the application is running in a RAM constrained device. If the the application is running in a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
IsRamConstrainedDevicePromise(){
app.isRamConstrainedDevicePromise().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
```
## appManager.isRamConstrainedDevice
isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void;
Checks whether this application is running in a RAM constrained device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the the application is running in a RAM constrained device. If the the application is running in a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
IsRamConstrainedDeviceCallBack(){
app.isRamConstrainedDevicePromise((err, data) => {
console.log('startAbility result failed:' + JSON.stringify(err));
console.log('startAbility result success:' + JSON.stringify(data));
})
}
```
## appManager.getAppMemorySize
getAppMemorySize(): Promise\<number>;
Obtains the memory size of this application. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;number&gt; | Size of the application memory.|
**Example**
```js
GetAppMemorySize(){
app.getAppMemorySize().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
```
## appManager.getAppMemorySize
getAppMemorySize(callback: AsyncCallback\<number>): void;
Obtains the memory size of this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.|
**Example**
```js
GetAppMemorySizeCallBack(){
app.getAppMemorySize((err, data) => {
console.log('startAbility result failed :' + JSON.stringify(err));
console.log('startAbility result success:' + JSON.stringify(data));
})
}
```
# Brightness
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The Brightness module provides an API for setting the screen brightness.
......@@ -14,19 +14,19 @@ import brightness from '@ohos.brightness';
## brightness.setValue
setValue(value: number)
setValue(value: number): void
Sets the screen brightness.
**System capability:** SystemCapability.PowerManager.DisplayPowerManager
This is a system API and cannot be called by third-party applications.
**Note:** This is a system API and it is used only for system applications.
**System capability:** SystemCapability.PowerManager.DisplayPowerManager
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----------- |
| value | number | Yes | Brightness value, ranging from 0 to 255.|
| value | number | Yes | Brightness value, ranging from **0** to **255**.|
**Example**
......
......@@ -10,17 +10,19 @@ Provides the configuration for the environment where the ability is running.
## Modules to Import
```
```js
import Configuration from '@ohos.application.Configuration';
```
## Attributes
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| language | string | Yes| Yes| Language of the application.|
| colorMode | [ColorMode](js-apis-configurationconstant.md) | Yes| Yes| Color mode, which can be **COLOR_MODE_LIGHT** or **COLOR_MODE_DARK**. The default value is **COLOR_MODE_LIGHT**.|
| direction | Direction | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.|
| screenDensity | ScreenDensity | Yes| No| Screen resolution, which can be **SCREEN_DENSITY_SDPI** (120), **SCREEN_DENSITY_MDPI** (160), **SCREEN_DENSITY_LDPI** (240), **SCREEN_DENSITY_XLDPI** (320), **SCREEN_DENSITY_XXLDPI** (480), or **SCREEN_DENSITY_XXXLDPI** (640).|
| displayId | number | Yes| No| ID of the display where the application is located.|
| direction<sup>9+</sup> | Direction | Yes| No| Screen orientation, which can be **DIRECTION_HORIZONTAL** or **DIRECTION_VERTICAL**.|
| screenDensity<sup>9+</sup> | ScreenDensity | Yes| No| Screen resolution, which can be **SCREEN_DENSITY_SDPI** (120), **SCREEN_DENSITY_MDPI** (160), **SCREEN_DENSITY_LDPI** (240), **SCREEN_DENSITY_XLDPI** (320), **SCREEN_DENSITY_XXLDPI** (480), or **SCREEN_DENSITY_XXXLDPI** (640).|
| displayId<sup>9+</sup> | number | Yes| No| ID of the display where the application is located.|
......@@ -10,46 +10,67 @@ Defines enumerated values of the configuration for the environment where the abi
## Modules to Import
```
```js
import ConfigurationConstant from '@ohos.application.ConfigurationConstant';
```
## ColorMode
## ConfigurationConstant.ColorMode
The value is obtained through the **ConfigurationConstant.ColorMode** API.
To obtain the value, use **ConfigurationConstant.ColorMode**, for example, **ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT**.
**Example**
```
ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT
```
| Name| Value| Description|
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description|
| -------- | -------- | -------- |
| COLOR_MODE_NOT_SET | -1 | Unspecified color mode.|
| COLOR_MODE_DARK | 0 | Dark mode.|
| COLOR_MODE_LIGHT | 1 | Light mode.|
## Direction
## ConfigurationConstant.Direction
To obtain the value, use **ConfigurationConstant.Direction**, for example, **ConfigurationConstant.Direction.DIRECTION_VERTICAL**.
The value is obtained through the **ConfigurationConstant.Direction** API.
**Example**
| Name| Value| Description|
```
ConfigurationConstant.Direction.DIRECTION_VERTICAL
```
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description|
| -------- | -------- | -------- |
| DIRECTION_NOT_SET | -1 | Unspecified direction.|
| DIRECTION_VERTICAL | 0 | Vertical direction.|
| DIRECTION_HORIZONTAL | 1 | Horizontal direction.|
| DIRECTION_NOT_SET<sup>9+</sup> | -1 | Unspecified direction.|
| DIRECTION_VERTICAL<sup>9+</sup> | 0 | Vertical direction.|
| DIRECTION_HORIZONTAL<sup>9+</sup> | 1 | Horizontal direction.|
## ConfigurationConstant.ScreenDensity
## ScreenDensity
The value is obtained through the **ConfigurationConstant.ScreenDensity** API.
To obtain the value, use **ConfigurationConstant.ScreenDensity**, for example, **ConfigurationConstant.ScreenDensity.SCREEN_DENSITY_NOT_SET**.
**Example**
```
ConfigurationConstant.ScreenDensity.SCREEN_DENSITY_NOT_SET
```
**System capability**: SystemCapability.Ability.AbilityBase
| Name| Value| Description|
| Name| Value| Description|
| -------- | -------- | -------- |
| SCREEN_DENSITY_NOT_SET | 0 | Unspecified screen resolution.|
| SCREEN_DENSITY_SDPI | 120 | The screen resolution is sdpi.|
| SCREEN_DENSITY_MDPI | 160 | The screen resolution is mdpi.|
| SCREEN_DENSITY_LDPI | 240 | The screen resolution is ldpi.|
| SCREEN_DENSITY_XLDPI | 320 | The screen resolution is xldpi.|
| SCREEN_DENSITY_XXLDPI | 480 | The screen resolution is xxldpi.|
| SCREEN_DENSITY_XXXLDPI | 640 | The screen resolution is xxxldpi.|
| SCREEN_DENSITY_NOT_SET<sup>9+</sup> | 0 | Unspecified screen resolution.|
| SCREEN_DENSITY_SDPI<sup>9+</sup> | 120 | The screen resolution is sdpi.|
| SCREEN_DENSITY_MDPI<sup>9+</sup> | 160 | The screen resolution is mdpi.|
| SCREEN_DENSITY_LDPI<sup>9+</sup> | 240 | The screen resolution is ldpi.|
| SCREEN_DENSITY_XLDPI<sup>9+</sup> | 320 | The screen resolution is xldpi.|
| SCREEN_DENSITY_XXLDPI<sup>9+</sup> | 480 | The screen resolution is xxldpi.|
| SCREEN_DENSITY_XXXLDPI<sup>9+</sup> | 640 | The screen resolution is xxxldpi.|
# ExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......@@ -11,4 +11,4 @@ Implements the extension context. This module is inherited from **Context**.
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br><b>System capabilities: </b>SystemCapability.Ability.AbilityRuntime.Core|
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.<br>**System capability**: SystemCapability.Ability.AbilityRuntime.Core |
此差异已折叠。
......@@ -9,7 +9,9 @@ Provides the permission request result.
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core|
| authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite. <br><b>System capability</b>: SystemCapability.Ability.AbilityRuntime.Core|
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested.|
| authResults | Array&lt;number&gt; | Yes| No| Whether the requested permissions are granted or denied. The value **0** means that the requests permissions are granted, and **-1** means the opposite. |
......@@ -350,7 +350,7 @@ var pres = process.getEnvironmentVar("PATH")
## process.runCmd
runCmd(command: string, options?: { timeout : number, killSignal : number | string, maxBuffer : number }) : ChildProcess
runCmd(command: string, options?: { timeout : number, killSignal : number | string, maxBuffer : number }): ChildProcess
Forks a new process to run a shell command and returns the **ChildProcess** object.
......@@ -527,7 +527,7 @@ var time = process.uptime();
## process.kill
kill(pid: number, signal: number ): boolean
kill(signal: number, pid: number): boolean
Sends a signal to the specified process to terminate it.
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册