picker:基于HarmonyOS的文件选择与媒体查看项目

应用使用@ohos.file.picker、@ohos.file.fs等接口,实现了picker拉起文档编辑保存、拉起系统相册图片查看、拉起视频并播放的功能。

Branch3Tags0
FilesLast commitLast update
1 year ago
2 years ago
4 months ago
1 year ago
1 year ago
2 years ago
5 months ago
5 months ago
1 year ago
2 years ago
2 years ago

Selecting and View Documents and Media Files

Overview

This sample shows how to select and save documents, select and view photos in the system album, and select and play videos.

Preview

Viewing and editing a document Viewing an image Viewing a video

How to Use

  1. On the home screen, tap the three buttons in the bottom to create a document, select and view an image or video, and select and open a document, respectively.
  2. On the document viewing page, tap the leftmost button on the upper right to save the document as a new one. Tap the button in the middle to edit the document. The text area becomes editable. After entering data, tap the third button in the upper right corner to save the document content (the system document is not editable).
  3. On the page for viewing images, the picker displays the images in the system album. You can select a maximum of four images to view. You can tap an image to view the image name and size.
  4. On the page for viewing video, the picker displays the videos in the system album. You can select a maximum of four images to view. You can tap a video to view the video name and size.

Library Directory

├──entry/src/main/ets/
│  ├──common
│  │  └──CommonConstants.ets             // Constants					
│  ├──component
│  │  ├──EditFile.ets                    // Page for viewing and editing a document
│  │  ├──PickerComponent.ets             // Home page
│  │  └──ViewMedia.ets                   // Page for viewing images and videos
│  ├──media
│  │  └──MediaFileUri.ets                // APIs for media files
│  ├──utils
│  │  ├──BreakpointSystem.ets            // Breakpoint utils
│  │  ├──StringUtils.ets                 // String utils
│  │  ├──Logger.ets                      // Log utils
│  │  └──WindowUtil.ets                  // Window utils	
│  └──PickerController.ets               // Export utils
└──entry/src/main/resources              // Static resources of the app

How to Implement

  • The APIs for starting picker to select or save documents and select images or videos are encapsulated in Index.ets. For details about the source code, see Index.ets.

    • Use new picker.DocumentViewPicker to create a document picker instance, use documentPicker.select to start picker for the user to select documents, and use documentPicker.save to start picker for the user to save documents. For details about the APIs, see @ohos.file.picker.
    • Use new photoAccessHelper.PhotoViewPicker to create a PhotoViewPicker instance, and use photoPicker.select to start picker for the user to select images or videos. For details about the APIs, see @ohos.file.photoAccessHelper.
  • The APIs for editing and saving files are encapsulated in EditFile.ets. For details about the source code, see EditFile.ets.

    • Use fs.openSync, fs.writeSync, fs.readSync, and fs.closeSync to open, write, read, and close files, respectively. For details about the APIs, see @ohos.file.fs.
  • The APIs for starting and viewing images or videos are encapsulated in ViewMedia.ets. For details about the source code, see ViewMedia.ets.

Required Permissions

N/A

Dependencies

N/A

Constraints

  1. The sample app is supported on Huawei phones, tablet, PC/2in1 running the standard system.

  2. The HarmonyOS version must be HarmonyOS 5.0.0 Release or later.

  3. The DevEco Studio version must be DevEco Studio 5.0.0 Release or later.

  4. The HarmonyOS SDK version must be HarmonyOS 5.0.0 Release or later.

Introduction

应用使用@ohos.file.picker、@ohos.file.fs等接口,实现了picker拉起文档编辑保存、拉起系统相册图片查看、拉起视频并播放的功能。

Customize your domain