This module provides the status awareness capability of file open boost for apps. An app can integrate with the corresponding APIs to detect the file open boost status, and then provide a unique user interface (UI) identifier for the boosted file, improving experience when opening the file.
System capability: SystemCapability.PCService.OpenFileBoost
Since: 5.0.5(17)
Deprecated since: 26.0.0
Enumerates the file preloading statuses.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.PCService.OpenFileBoost
Since: 5.0.5(17)
Deprecated since: 26.0.0
| Name | Value | Description |
|---|---|---|
| NOT_PRELOADED | 0 | The file is not preloaded. |
| PRELOADING | 1 | The file is preloading. |
| PRELOADED | 2 | File preloading completed. |
Describes the file preloading status information.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.PCService.OpenFileBoost
Since: 5.0.5(17)
Deprecated since: 26.0.0
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| sandboxPath | string | No | No | Sandbox path of the file. The value length range is [1, 1024]. |
| progress | number | No | No | File preloading progress. |
| state | FilePreloadState | No | No | File preloading status. |
on(type: 'filePreloadStateChanged', callback: Callback<FilePreloadStatusInfo>): void
Registers the callback for file preloading status events. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.PCService.OpenFileBoost
Since: 5.0.5(17)
Deprecated since: 26.0.0
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event callback type, which is fixed to filePreloadStateChanged. This event is triggered whenever the file preloading status changes, returning the corresponding information. If a value other than filePreloadStateChanged is set, the registration will be successful, but the file preloading status change cannot be obtained. |
| callback | Callback<FilePreloadStatusInfo> | Yes | Callback used to return the file preloading status. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | Parameter error.Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
| 1017220001 | Internal failure. |
| 1017220002 | Service unavailable. |
Example:
In the example, filePreloadStatusInfo is a parameter passed by the system callback. For details, please refer to the FilePreloadStatusInfo API description.
import { openFileBoost } from '@kit.PreviewKit';
import { BusinessError } from '@kit.BasicServicesKit';
function callback(filePreloadStatusInfo: openFileBoost.FilePreloadStatusInfo): void {
if (filePreloadStatusInfo.state === openFileBoost.FilePreloadState.PRELOADING) {
// The file is preloading, and the app can customize its UX design.
console.info(`file is PRELOADING, suggest to show loading animation`);
}
if (filePreloadStatusInfo.state === openFileBoost.FilePreloadState.PRELOADED) {
// Preloading is complete, and the app can display a boost completion message.
console.info(`file is PRELOADED, suggest to show loaded animation`);
}
if (filePreloadStatusInfo.state === openFileBoost.FilePreloadState.NOT_PRELOADED) {
// No file is preloaded, and the app displays nothing.
console.info(`file is UNPRELOADED, suggest do not show animation `);
}
}
openFileBoost.on('filePreloadStateChanged', callback); off(type: 'filePreloadStateChanged', callback?: Callback<FilePreloadStatusInfo>): void
Unregisters the callback for file preloading status events. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.PCService.OpenFileBoost
Since: 5.0.5(17)
Deprecated since: 26.0.0
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event callback type, which is fixed to filePreloadStateChanged. This event is triggered whenever the file preloading status changes, returning the corresponding information. If a value other than filePreloadStateChanged is set, the function of obtaining the file preloading status change cannot be canceled. |
| callback | Callback<FilePreloadStatusInfo> | No | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | Parameter error.Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
| 1017220001 | Internal failure. |
| 1017220002 | Service unavailable. |
Example:
In the example, filePreloadStatusInfo is a parameter passed by the system callback. For details, please refer to the FilePreloadStatusInfo API description.
import { openFileBoost } from '@kit.PreviewKit';
import { BusinessError } from '@kit.BasicServicesKit';
function callback1(filePreloadStatusInfo: openFileBoost.FilePreloadStatusInfo): void {
console.info(`on filePreloadStateChanged in callback1`);
}
function callback2(filePreloadStatusInfo: openFileBoost.FilePreloadStatusInfo): void {
console.info(`on filePreloadStateChanged in callback2`);
}
function callback3(filePreloadStatusInfo: openFileBoost.FilePreloadStatusInfo): void {
console.info(`on filePreloadStateChanged in callback3`);
}
openFileBoost.on('filePreloadStateChanged', callback1);
openFileBoost.on('filePreloadStateChanged', callback2);
openFileBoost.on('filePreloadStateChanged', callback3);
// To cancel only the listening of callback1, pass callback1 as a parameter. Then callback1 will not be called for notification.
openFileBoost.off('filePreloadStateChanged', callback1);
// To cancel the listening of all callbacks, do not specify the second optional parameter. Then callback2 and callback3 will not be called for notification.
openFileBoost.off('filePreloadStateChanged'); addFile(file: string): void
Listener for the file preloading status, which is used to listen to the file preloading status after the app passes the file path. If the file status changes, the change is returned to the app through the filePreloadStateChanged event callback. You need to call openFileBoost.on('filePreloadStateChanged') before calling this API to add a listener for file preloading status. Currently, an app can add a maximum of 50 file listeners.
For details about the file types that support boost, please refer to File Types Supported by File Open Boost. For file types that are not supported, the file will not be preloaded by default. In this case, you do not need to call this API to listen for the file preloading status change.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.PCService.OpenFileBoost
Since: 5.0.5(17)
Deprecated since: 26.0.0
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| file | string | Yes | Sandbox path of the file. The value length range is [1, 1024]. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | Parameter error.Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
| 1017220001 | Internal failure. |
| 1017220002 | Service unavailable. |
| 1017220003 | The number of files exceeds the upper limit. |
Example:
In the example, filePreloadStatusInfo is a parameter passed by the system callback. For details, please refer to the FilePreloadStatusInfo API description.
import { openFileBoost } from '@kit.PreviewKit';
import { BusinessError } from '@kit.BasicServicesKit';
const file: string = "/storage/Users/currentUser/Desktop/10MB_file.docx";
function fileStateChangedCallback(filePreloadStatusInfo: openFileBoost.FilePreloadStatusInfo): void {
console.info(`on filePreloadStateChanged, state: ${filePreloadStatusInfo.state}`);
}
openFileBoost.on('filePreloadStateChanged', fileStateChangedCallback);
openFileBoost.addFile(file); removeFile(file: string): void
Cancels the listening for the preloading status of a file. The preloading status change will not be notified to the app through callback.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.PCService.OpenFileBoost
Since: 5.0.5(17)
Deprecated since: 26.0.0
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| file | string | Yes | Sandbox path of the file. The value length range is [1, 1024]. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | Parameter error.Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
| 1017220001 | Internal failure. |
| 1017220002 | Service unavailable. |
Example:
import { openFileBoost } from '@kit.PreviewKit';
import { BusinessError } from '@kit.BasicServicesKit';
const file: string = "/storage/Users/currentUser/Desktop/10MB_file.docx";
openFileBoost.removeFile(file); queryFilePreloadStatusInfo(file: string): FilePreloadStatusInfo
Queries the preloading status of a file. The file preloading status will be returned after the file path is passed.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.PCService.OpenFileBoost
Since: 5.0.5(17)
Deprecated since: 26.0.0
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| file | string | Yes | Sandbox path of the file. The value length range is [1, 1024]. |
Returns:
| Type | Description |
|---|---|
| FilePreloadStatusInfo | File preloading status information. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | Parameter error.Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
| 1017220001 | Internal failure. |
| 1017220002 | Service unavailable. |
Example:
import { openFileBoost } from '@kit.PreviewKit';
import { BusinessError } from '@kit.BasicServicesKit';
const file: string = "/storage/Users/currentUser/Desktop/10MB_file.docx";
let statusInfo: openFileBoost.FilePreloadStatusInfo = openFileBoost.queryFilePreloadStatusInfo(file);
console.info(`file, ${statusInfo.sandboxPath}, progress:${statusInfo.progress} preloadState:${statusInfo.state}`);