提交 1de96fac 编写于 作者: G Gloria

Update docs against 11242+11318

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 0612bb09
# FAQs
- [Ability Framework Development](faqs-ability.md)
- [ArkUI (JavaScript) Development](faqs-ui-js.md)
- [Bundle Management Development](faqs-bundle.md)
- [ArkUI (eTS) Development](faqs-ui-ets.md)
- [ArkUI (JavaScript) Development](faqs-ui-js.md)
- [Graphics and Image Development](faqs-graphics.md)
- [File Management Development](faqs-file-management.md)
- [Media Development](faqs-media.md)
- [Network and Connection Development](faqs-connectivity.md)
- [Data Management Development](faqs-data-management.md)
- [Device Management Development](faqs-device-management.md)
......
......@@ -4,7 +4,7 @@
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
A guide is available for the **DataShareExtensionAbility** class in the stage model, which provides APIs for sharing data with other applications and managing the data.
A guide is available for the **DataShareExtensionAbility** class, which provides APIs for sharing data with other applications and managing the data, in the stage model.
Reference: [DataShare Development](../database/database-datashare-guidelines.md)
......@@ -20,6 +20,32 @@ Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Reference: [Release Testing Version](https://gitee.com/openharmony-sig/oh-inner-release-management/blob/master/Release-Testing-Version.md)
## How do I set the UI of an ability to transparent?
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Set the background color of the top container component to transparent, and then set the **opacity** attribute of the XComponent to **0.01**.
Example:
```
build() {
Stack() {
XComponent({
id: 'componentId',
type: 'surface',
})
.width('100%')
.height('100%')
.opacity(0.01)
// Page content
}
.width('100%')
.height('100%')
.backgroundColor('rgba(255,255,255, 0)')
}
```
## How do I prevent "this" in a method from changing to "undefined" when the method is called?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
......@@ -36,7 +62,7 @@ Configure the **startWindowIcon** attribute under **abilities** in the **module.
Reference: [Application Package Structure Configuration File](../quick-start/stage-structure.md)
Example:
Example:
```
{
......@@ -58,3 +84,133 @@ Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Implement the **onConfigurationUpdated** callback in the **Ability** class. The callback is triggered when the system language, color mode, or display parameters (such as the orientation and density) change.
Reference: [Ability Development](../ability/stage-ability.md)
## Can I obtain the context through globalThis in the stage model?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
Do not use **globalThis** to obtain the context in the stage model. This is because all the processes of an application share a JS VM instance in the stage model. Multiple abilities can run on these processes and share the same global object. If **globalThis** is used, the context of different abilities of the same JS VM instance may be returned.
For details about the recommended operation, see [Context in the Stage Model](../ability/context-userguide.md#context-in-the-stage-model).
## How do I obtain the HAP file installation path of application B from application A?
Applicable to: OpenHarmony SDK 3.0 or later, stage model of API version 9
First, request the system permission. For details, see [Having Your App Automatically Signed](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-auto-configuring-signature-information-0000001271659465). Then, import the **bundle** module, and call **bundle.getApplicationInfo()** to obtain application information based on the bundle name. Finally, use **application.moduleSourceDirs** to obtain the application storage path.
## How is data returned when startAbilityForResult is called?
Applicable to: OpenHarmony SDK3.0, stage model of API version 9
The callee uses **AbilityContext.terminateSelfWithResult** to destroy its ability and pass parameters to **startAbilityForResult**. For details, see [AbilityContext](../reference/apis/js-apis-ability-context.md#abilitycontextterminateselfwithresult).
## Can the lifecycle callback of a released FA widget be triggered when the widget is displayed in the service center so that the user login information can be obtained without opening the FA application?
Applicable to: OpenHarmony SDK 3.2.5.5, FA model of API version 8
After a widget is added, the **onCreate()** lifecycle is triggered so that related user information (silent login) can be displayed even when the application is not started. However, users must manually add the widget after the application is installed.
## How do I obtain the context?
Applicable to: OpenHarmony SDK 3.2.7.5, stage model of API version 9
You can use **this.context** to obtain the context in the **MainAbility.ts** file or call **getContext(this)** to obtain the context on the component page.
## What should I do when undefined is displayed for the calling of **abilityAccessCtrl.grantUserGrantedPermission** during API version 8 syntax verification?
Applicable to: OpenHarmony SDK 3.0, FA model of API version 8
**abilityAccessCtrl.grantUserGrantedPermission** is a system API. It is not available in the public SDK, which is provided as default on DevEco Studio. To use system APIs, switch to the full SDK. For details, see [Guide to Switching to Full SDK](../quick-start/full-sdk-switch-guide.md).
## Which of the following Extension abilities are available in the public SDK: ServiceExtensionAbility, FormExtensionAbility, and DataShareExtensionAbility?
Applicable to: OpenHarmony SDK 3.2.5.6, stage model of API version 9
Among the aforementioned Extension abilities, only **FormExtensionAbility** is available in the public SDK. **ServiceExtensionAbility** and **DataShareExtensionAbility** are system APIs and available only in the full SDK.
Public SDK: intended for application developers and does not contain system APIs that require system permissions.
Full SDK: intended for original equipment manufacturers (OEMs) and contains system APIs that require system permissions.
## Why can't I play GIF images cyclically on the widget?
Applicable to: OpenHarmony SDK 3.2.5.6, stage model of API version 9
The system does not support the display of GIF images on the widget.
## How do I implement service login by touching a widget?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
You can start an ability upon the touch and implement service login in the ability.
## How do I redirect to the application details page in Settings?
Applicable to: OpenHarmony SDK 3.2.6.5
Refer to the following code:
```
this.context.startAbility(
{
action: "action.settings.app.info",
parameters: { "settingsParamBundleName": "your app bundlename" }
})
```
## How do I listen for screen rotation events?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
Refer to the following code:
```
let listener = mediaquery.matchMediaSync('(orientation: landscape)')
onPortrait(mediaQueryResult) {
if (mediaQueryResult.matches) {
// Do something here.
} else {
// Do something here.
}
}
listener.on('change', onPortrait)
```
## How do I control the shadow background size during checkbox selection?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
Set the **padding** attribute of the **\<checkbox>** component to control the shadow size.
## How do I set the widget background to transparent?
Applicable to: OpenHarmony SDK 3.2.5.5
1. Create the **widget/resources/styles/default.json** file in the root directory of the widget.
2. Add the following code to the **default.json** file:
```
{
"style": {
"app_background": "#00000000"
}
}
```
## How do I pass parameters for FA widgets?
Applicable to: OpenHarmony SDK 3.2.5.5
Use **featureAbility.getWant()** and **featureAbility.getContext()** to send data through **router** in the JSON file and use **featureAbility** to receive data in the JS file.
## How do I trigger router.disableAlertBeforeBackPage and router.enableAlertBeforeBackPage?
Applicable to: OpenHarmony SDK 3.2.5.5
The following conditions must be met:
1. Before the redirection to the previous page, a confirm dialog box will be displayed. Note that **router.disableAlertBeforeBackPage** is used to disable the display of a confirm dialog box before returning to the previous page (default), and **router.enableAlertBeforeBackPage** is used to enable the display.
2. The system return key is used.
# Bundle Management Development
## How do I obtain the version code and version name of an application?
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Use **bundle.getBundleInfo()** to obtain the bundle information, which contains the version code and version name.
Reference: [Bundle](../reference/apis/js-apis-Bundle.md#bundlegetbundleinfo)
## How do I obtain the bundle name of an application?
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Obtain the bundle name through **context.abilityInfo.bundleName**.
Reference: [AbilityContext](../reference/apis/js-apis-ability-context.md) and [AbilityInfo](../reference/apis/js-apis-bundle-AbilityInfo.md)
## How do I obtain an application icon?
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Use **bundle.getAbilityIcon** to obtain the application icon. To use this API, you must configure the permission **ohos.permission.GET_BUNDLE_INFO**.
Reference: [Bundle](../reference/apis/js-apis-Bundle.md#bundlegetbundleinfo)
## How do I determine whether an application is a system application?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
Use **bundle.getApplicationInfo** to obtain the application information, and then check the value of **systemApp** in the information. The application is a system application if the value is **true**.
......@@ -11,3 +11,80 @@ In effect, the **isStatusBarLightIcon** and **isNavigationBarLightIcon** attribu
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Import the **\@ohos.window** module, and call **window.setSystemBarProperties()**.
## How do I hide the status bar to get the immersive effect?
Applicable to: OpenHarmony SDK 3.2.6.3, stage model of API version 9
1. Use the **onWindowStageCreate** to obtain a **windowClass** object.
```
onWindowStageCreate(windowStage) {
// When the main window is created, set the main page for this ability.
console.log("[Demo] MainAbility onWindowStageCreate")
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window.')
return;
}
// Obtain a windowClass object.
globalThis.windowClass = data;
})
}
```
2. Enable the full-screen mode for the window and hide the status bar.
```
globalThis.windowClass.setFullScreen(isFullScreen, (err, data) => {
if (err.code) {
console.error('Failed to enable the full-screen mode. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
});
```
## How do I obtain the window width and height?
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
Use **window.getProperties()** to obtain the window properties. The **windowRect** field in the properties specifies the window width and height.
Example:
```
let promise = windowClass.getProperties();
promise.then((data)=> {
console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data.windowRect));
}).catch((err)=>{
console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err));
});
```
## How do I set the color of the system bar?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
Refer to the following code:
```
window.getTopWindow(globalThis.mainContext).then(win => {
var systemBarProperties = {
statusBarColor: '#19B6FF', // Set the background color of the status bar.
navigationBarColor: '#19B6FF', // Set the background color of the navigation bar.
isStatusBarLightIcon: false, // Set the icon on the status bar not to be highlighted.
isNavigationBarLightIcon: true, // Set the icon on the navigation bar to be highlighted.
statusBarContentColor: '#0D0500', // Set the text color of the status bar.
navigationBarContentColor: '#FFA500' // Set the text color of the navigation bar.
};
win.setSystemBarProperties(systemBarProperties).catch(err => {
INDEX_LOGGER.info(`set System Bar Properties failed:${err}`)
})
})
.catch(err => {
INDEX_LOGGER.info(`get top window failed:${err}`)
})
```
# Media Development
## How do I set a front camera?
Applicable to: OpenHarmony SDK 3.2.3.5, stage model of API version 9
1. Set the camera position to **camera.CameraPosition.CAMERA_POSITION_FRONT**.
2. Create a **CameraInput** instance based on the camera position and type.
Reference: [Camera Management](../reference/apis/js-apis-camera.md)
Example:
```
// The rear camera is set by default. You can use **isFrontCamera** to switch to the rear camera.
let cameraId
let cameraInput
for(let cameraIndex = 0; cameraIndex < this.cameraArray.length; cameraIndex++) {
let faceType = this.cameraArray[cameraIndex].cameraPosition
switch(faceType) {
case camera.CameraPosition.CAMERA_POSITION_FRONT: // Front camera
if(this.isFrontCamera){
cameraId = this.cameraArray[cameraIndex].cameraId
}
break
case camera.CameraPosition.CAMERA_POSITION_BACK: // Rear camera
if(!this.isFrontCamera){
cameraId = this.cameraArray[cameraIndex].cameraId
}
break
case camera.CameraPosition.CAMERA_POSITION_UNSPECIFIED:
default:
break
}
}
cameraInput = await this.cameraManager.createCameraInput(cameraId)
```
## How do I crop an image?
Applicable to: OpenHarmony SDK 3.2.5.6, stage model of API version 9
1. Create an **ImageSource** instance based on the input URI.
```
let path = this.context.getApplicationContext().fileDirs + "test.jpg";
const imageSourceApi = image.createImageSource(path);
```
2. Set decoding parameters and decode the image to obtain a **PixelMap** object. Image processing is supported during decoding.
- Set **desiredSize** to specify the target size after scaling. If the values are all set to **0**, scaling will not be performed.
- Set **desiredRegion** to specify the target rectangular area after cropping. If the values are all set to **0**, cropping will not be performed.
- Set **rotateDegrees** to specify the rotation angle. The image will be rotated clockwise at the center.
```
const decodingOptions = {
desiredSize: {
height:0,
width:0
},
// Crop a rectangular area.
desiredRegion: {
size: {
height:100,
width:100
},
x:0,
y:0
},
// Rotate the image by 90 degrees.
rotate:90
}
imageSourceApi.createPixelMap(decodingOptions).then(pixelMap => {
this.handlePixelMap(pixelMap)
})
```
3. Process the obtained **PixelMap** object. For example, render and display the image.
## How do I apply for the media read/write permission on a device?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
1. Configure the permissions **ohos.permission.READ_MEDIA** and **ohos.permission.WRITE_MEDIA** in the **module.json5** file.
Example:
```
{
"module" : {
"requestPermissions":[
{
"name" : "ohos.permission.READ_MEDIA",
"reason": "$string:reason"
},
{
"name" : "ohos.permission.WRITE_MEDIA",
"reason": "$string:reason"
}
]
}
}
```
2. Call **requestPermissionsFromUser** to request the permissions from end users in the form of a dialog box. This operation is required because the grant mode of both permissions is **user_grant**.
```
let permissions: Array<string> = ['ohos.permission.READ_MEDIA','ohos.permission.WRITE_MEDIA']
context.requestPermissionsFromUser(permissions).then((data) => {
console.log("Succeed to request permission from user with data: " + JSON.stringify(data))
}).catch((error) => {
console.log("Failed to request permission from user with error: " + JSON.stringify(error))
})
```
## Why can't I play MP4 videos?
Applicable to: OpenHarmony SDK 3.2.7.5, stage model of API version 9
Currently, the system does not support the playback of MP4 videos in H.265 format.
## Why can't I play a new video or even encounters a crash after creating more than 10 videos?
Applicable to: OpenHarmony SDK 3.2.7.5, stage model of API version 9
A maximum of 13 media player instances can be created.
# Native API Usage
## Is there a native API that provides functions similar to Canvas?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Yes. The native API **Drawing** provides similar functions. It can be used for 2D drawing.
## When a native HAP is running, the error message "Obj is not a valid object" is displayed for the imported namespace. What should I do?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Check the **abiFilters** parameter value in the **build-profile.json5** file in the root directory of the module (not the root directory of the project). If the device is 32-bit, the value must be **armeabi-v7a**. If the device is 64-bit, the value must be **arm64-v8a**.
## How do I obtain the value of version in the package.json file of a module in the C++ code developed using native APIs?
## What should I do when the error message "install parse profile prop check error" is displayed during the running of a native HAP?
Applicable to: OpenHarmony SDK 3.2.6.3, stage model of API version 9
Check the **abiFilters** parameter value in the **build-profile.json5** file in the root directory of the module (not the root directory of the project). If the device is 32-bit, the value must be **armeabi-v7a**. If the device is 64-bit, the value must be **arm64-v8a**.
## What should I do when the error message "undefined symbol: OH_LOG_Print" is displayed during log printing by **OH_LOG_Print**?
Applicable to: OpenHarmony SDK 3.2.6.3, stage model of API version 9
Modify the **CMakeLists.txt** file by adding **libhilog_ndk.z.so** to the end of **target_link_libraries**.
## How do I obtain the value of version in the package.json file of a module?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
......@@ -53,3 +71,9 @@ static napi_value Add(napi_env env, napi_callback_info info)
return fixed_version_value;
}
```
## How do I traverse files in rawfile?
Applicable to: OpenHarmony SDK 3.2 or later, stage model of API version 9
Use the native API **OH_ResourceManager_OpenRawDir()** to obtain the root directory of **rawfile** and traverse the root directory.
# Usage of Third- and Fourth-Party Libraries
## What does the following error message mean : "Stage model module... does not support including OpenHarmony npm packages or modules in FA model. OpenHarmony build tasks will not be executed, and OpenHarmony resources will not be packed."
## What does the following error message mean: "Stage model module... does not support including OpenHarmony npm packages or modules in FA model. OpenHarmony build tasks will not be executed, and OpenHarmony resources will not be packed."
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
The third- and fourth-party libraries are not yet compatible with the stage model of API version 9 and cannot be used.
## Can I transfer project-level dependencies?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
For example, if project A depends on project B and project B depends on project C, can project A directly use the APIs provided by project C?
No. Project A cannot directly use the APIs provided by project C. The project packing tool NPM does not support dependency transfer. To use the APIs provided by project C, you can add the dependency of project C to project A.
## How do I obtain available third-party libraries?
Applicable to: OpenHarmony SDK 3.2.6.5, stage model of API version 9
For details, see [Third-Party Components That Can Be Directly Used on OpenHarmony](https://gitee.com/openharmony-sig/third_party_app_libs).
## Which third-party libraries are related to network requests?
Applicable to: OpenHarmony SDK 3.2.6.5, stage model of API version 9
The [Axios](https://gitee.com/openharmony-sig/axios) library is related to network requests.
## How do I use NPM to import third- and fourth-party libraries?
Applicable to: OpenHarmony SDK 3.2.5.5, stage model of API version 9
- Method 1:
1. Open the **Terminal** window and run the following command to go to the **entry** directory:
```
cd entry
```
2. Run the following command to install a third-party package, for example, **dayjs**:
```
npm install dayjs --save
```
3. Add the following statement in the .js file to import the package:
```
import dayjs from 'dayjs';
```
- Method 2:
1. Enter the **entry** directory of the project and open the **package.json** file.
2. Write the third-party NPM package to be installed (for example, **dayjs**) in the **package.json** file.
```
{
"dependencies": {
"dayjs": "^1.10.4",
}
}
```
3. Open the **Terminal** window and run the following command to go to the **entry** directory:
```
cd entry
```
4. Run the following command to install NPM:
```
npm install
```
5. Add the following statement in the .js file to import the package:
```
import dayjs from 'dayjs';
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册