文档管理中心
您当前正在浏览HarmonyOS最新文档,覆盖已发布的所有API版本,可在API参考中筛选您使用的API版本。详细的版本配套关系请参考版本说明
API参考应用服务Preview Kit(文件预览服务)ArkTS APIopenFileBoost(文件打开加速)(已废弃)

openFileBoost(文件打开加速)(已废弃)

PC/2in15.0.5(17)+Tablet26.0.0+

本模块为应用提供文件打开加速状态感知能力。应用可以通过接入对应API,感知文件的加速状态,进而应用可以实现对已加速文件给出独特的UI(user interface)标识等功能,优化用户文件打开体验。

系统能力: SystemCapability.PCService.OpenFileBoost

起始版本: 5.0.5(17)

废弃版本: 26.0.0

导入模块

收起
自动换行
深色代码主题
复制
  1. import { openFileBoost } from '@kit.PreviewKit';

FilePreloadState(deprecated)

PC/2in15.0.5(17)+Tablet26.0.0+

表示文件预加载状态的枚举。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.PCService.OpenFileBoost

起始版本: 5.0.5(17)

废弃版本: 26.0.0

展开
名称 说明
NOT_PRELOADED 0 文件未预加载。
PRELOADING 1 文件预加载中。
PRELOADED 2 文件预加载完成。

FilePreloadStatusInfo(deprecated)

PC/2in15.0.5(17)+Tablet26.0.0+

文件预加载回调返回的接口实例,表示文件的预加载状态信息。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.PCService.OpenFileBoost

起始版本: 5.0.5(17)

废弃版本: 26.0.0

展开
名称 类型 只读 可选 说明
sandboxPath string 文件的沙箱路径,字符长度范围:[1, 1024]。
progress number 文件预加载进度。
state FilePreloadState 文件预加载状态。

openFileBoost.on('filePreloadStateChanged')(deprecated)

PC/2in15.0.5(17)+Tablet26.0.0+

on(type: 'filePreloadStateChanged', callback: Callback<FilePreloadStatusInfo>): void

文件预加载状态回调,应用通过注册回调函数获取文件预加载的状态变化。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.PCService.OpenFileBoost

起始版本: 5.0.5(17)

废弃版本: 26.0.0

参数:

展开
参数名 类型 必填 说明
type string 事件回调类型,固定为'filePreloadStateChanged',每当预加载文件状态变化时都会触发该事件并返回对应信息。如填入'filePreloadStateChanged'以外的值,将注册成功但无法获取文件预加载的状态变化。
callback Callback<FilePreloadStatusInfo> 回调函数,用于应用获取预加载文件状态变化信息。

错误码:

以下错误码的详细介绍请参见通用错误码模块错误码

展开
错误码ID 错误信息
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.

示例:

示例中的filePreloadStatusInfo是系统回调传入的参数,详见上方FilePreloadStatusInfo接口定义。

收起
自动换行
深色代码主题
复制
  1. import { openFileBoost } from '@kit.PreviewKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. function callback(filePreloadStatusInfo: openFileBoost.FilePreloadStatusInfo): void {
  4. if (filePreloadStatusInfo.state === openFileBoost.FilePreloadState.PRELOADING) {
  5. // 预加载过程中,应用可以根据自己设计对应UX
  6. console.info(`file is PRELOADING, suggest to show loading animation`);
  7. }
  8. if (filePreloadStatusInfo.state === openFileBoost.FilePreloadState.PRELOADED) {
  9. // 预加载完成,应用可以通过UX显示提示用户加速完成
  10. console.info(`file is PRELOADED, suggest to show loaded animation`);
  11. }
  12. if (filePreloadStatusInfo.state === openFileBoost.FilePreloadState.NOT_PRELOADED) {
  13. // 没有预加载,应用可以不显示任何额外UX
  14. console.info(`file is UNPRELOADED, suggest do not show animation `);
  15. }
  16. }
  17. openFileBoost.on('filePreloadStateChanged', callback);

openFileBoost.off('filePreloadStateChanged')(deprecated)

PC/2in15.0.5(17)+Tablet26.0.0+

off(type: 'filePreloadStateChanged', callback?: Callback<FilePreloadStatusInfo>): void

文件预加载状态注销回调,通过注销回调函数取消获取文件预加载的状态变化。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.PCService.OpenFileBoost

起始版本: 5.0.5(17)

废弃版本: 26.0.0

参数:

展开
参数名 类型 必填 说明
type string 事件回调用类型,固定为'filePreloadStateChanged',当预加载文件状态变化时会触发该事件并返回对应信息。如填入'filePreloadStateChanged'以外的值,将无法取消获取文件预加载的状态变化。
callback Callback<FilePreloadStatusInfo> 回调函数,如果指定参数则取消对应callback(callback对象不可是匿名函数),否则取消所有callback。

错误码:

以下错误码的详细介绍请参见通用错误码模块错误码

展开
错误码ID 错误信息
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.

示例:

示例中的filePreloadStatusInfo是系统回调传入的参数,详见上方FilePreloadStatusInfo接口定义。

收起
自动换行
深色代码主题
复制
  1. import { openFileBoost } from '@kit.PreviewKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. function callback1(filePreloadStatusInfo: openFileBoost.FilePreloadStatusInfo): void {
  4. console.info(`on filePreloadStateChanged in callback1`);
  5. }
  6. function callback2(filePreloadStatusInfo: openFileBoost.FilePreloadStatusInfo): void {
  7. console.info(`on filePreloadStateChanged in callback2`);
  8. }
  9. function callback3(filePreloadStatusInfo: openFileBoost.FilePreloadStatusInfo): void {
  10. console.info(`on filePreloadStateChanged in callback3`);
  11. }
  12. openFileBoost.on('filePreloadStateChanged', callback1);
  13. openFileBoost.on('filePreloadStateChanged', callback2);
  14. openFileBoost.on('filePreloadStateChanged', callback3);
  15. // 单独取消callback1的监听,传入callback1作为参数,后续不会再调用callback1的回调做通知
  16. openFileBoost.off('filePreloadStateChanged', callback1);
  17. // 取消所有callback的监听,不传第二个可选参数,后续不会再调用callback2和callback3做通知
  18. openFileBoost.off('filePreloadStateChanged');

openFileBoost.addFile(deprecated)

PC/2in15.0.5(17)+Tablet26.0.0+

addFile(file: string): void

监听一个文件的预加载状态,应用传入文件路径后系统开始监听该文件的预加载状态。后续该文件状态有变化时系统通过'filePreloadStateChanged'事件回调向应用返回文件预加载状态变化。需要先调用openFileBoost.on('filePreloadStateChanged')接口后再调用该接口添加文件预加载状态监听,且当前一个应用最多添加50个文件监听。

当前支持加速的文件类型见文件打开加速支持的文件类型,不支持的文件类型默认为未预加载状态,不需要调用该接口监听文件预加载状态变更。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.PCService.OpenFileBoost

起始版本: 5.0.5(17)

废弃版本: 26.0.0

参数:

展开
参数名 类型 必填 说明
file string 文件的沙箱路径,字符长度范围:[1, 1024]。

错误码:

以下错误码的详细介绍请参见通用错误码模块错误码

展开
错误码ID 错误信息
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.

示例:

示例中的filePreloadStatusInfo是系统回调传入的参数,详见上方FilePreloadStatusInfo接口定义。

收起
自动换行
深色代码主题
复制
  1. import { openFileBoost } from '@kit.PreviewKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. const file: string = "/storage/Users/currentUser/Desktop/10MB_file.docx";
  4. function fileStateChangedCallback(filePreloadStatusInfo: openFileBoost.FilePreloadStatusInfo): void {
  5. console.info(`on filePreloadStateChanged, state: ${filePreloadStatusInfo.state}`);
  6. }
  7. openFileBoost.on('filePreloadStateChanged', fileStateChangedCallback);
  8. openFileBoost.addFile(file);

openFileBoost.removeFile(deprecated)

PC/2in15.0.5(17)+Tablet26.0.0+

removeFile(file: string): void

取消监听一个文件的预加载状态,取消后文件的预加载状态变化不会通过回调再通知应用。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.PCService.OpenFileBoost

起始版本: 5.0.5(17)

废弃版本: 26.0.0

参数:

展开
参数名 类型 必填 说明
file string 文件的沙箱路径,字符长度范围:[1, 1024]。

错误码:

以下错误码的详细介绍请参见通用错误码模块错误码

展开
错误码ID 错误信息
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.

示例:

收起
自动换行
深色代码主题
复制
  1. import { openFileBoost } from '@kit.PreviewKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. const file: string = "/storage/Users/currentUser/Desktop/10MB_file.docx";
  4. openFileBoost.removeFile(file);

openFileBoost.queryFilePreloadStatusInfo(deprecated)

PC/2in15.0.5(17)+Tablet26.0.0+

queryFilePreloadStatusInfo(file: string): FilePreloadStatusInfo

查询文件预加载状态,传入文件路径,通过返回值返回该文件当前的预加载状态。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.PCService.OpenFileBoost

起始版本: 5.0.5(17)

废弃版本: 26.0.0

参数:

展开
参数名 类型 必填 说明
file string 文件的沙箱路径,字符长度范围:[1, 1024]。

返回值:

展开
类型 说明
FilePreloadStatusInfo 文件预加载状态信息。

错误码:

以下错误码的详细介绍请参见通用错误码模块错误码

展开
错误码ID 错误信息
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.

示例:

收起
自动换行
深色代码主题
复制
  1. import { openFileBoost } from '@kit.PreviewKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. const file: string = "/storage/Users/currentUser/Desktop/10MB_file.docx";
  4. let statusInfo: openFileBoost.FilePreloadStatusInfo = openFileBoost.queryFilePreloadStatusInfo(file);
  5. console.info(`file, ${statusInfo.sandboxPath}, progress:${statusInfo.progress} preloadState:${statusInfo.state}`);
在 API参考 中进行搜索
请输入您想要搜索的关键词