HarmonyOS 如何获取手机上所有可访问目录下的PDF文件列表

上传体检报告时,可以选择手机上所有的PDF文件, 这个场景如何实现,主要是不知道如果获取手机上所有的PDF文件

HarmonyOS
2024-12-23 16:46:15
837浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

请尝试以下代码是否满足您的需求:

import picker from '@ohos.file.picker';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  DocSel() {
    let docSel = new picker.DocumentSelectOptions();
    let docPic = new picker.DocumentViewPicker();
    docSel.selectMode = picker.DocumentSelectMode.FILE;
    docSel.fileSuffixFilters = ['.pdf'];
    docPic.select(docSel).then((documentSelectResult: Array<string>) => {
      console.info('DocumentViewPicker.select successfully, documentSelectResult uri: ' + JSON.stringify(documentSelectResult));
    }).catch((err: BusinessError) => {
      console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
    });
  }

  build() {
    RelativeContainer() {
      Button("test")
        .onClick(() => {
          this.DocSel()
        })
    }
    .height('100%')
    .width('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
分享
微博
QQ
微信
回复
2024-12-23 19:34:51
相关问题
如何获取工程目录下json文件
1726浏览 • 1回复 待解决
如何动态访问media目录下资源
3085浏览 • 1回复 待解决
鸿蒙如何读取resources目录下文件
4487浏览 • 1回复 待解决
如何获取手机上部高度
1249浏览 • 1回复 待解决