• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Gallery Widget
2
3### Introduction
4
5This sample demonstrates the display of **Gallery** images in a widget and periodic update of the widget. The display effect is as follows:
6
7![](screenshots/device/gallery.png) ![](screenshots/device/gallery_form.png)
8
9### Concepts
10
11Media library management: You can use **getAllObject** of the media library instance to query the paths of all images in **Gallery**, and use **open** to obtain the file descriptor (FD) of an image in the specified path. This FD will be used as a key parameter for creating a widget.
12
13Widget update: You can use **formProvider.setFormNextRefreshTime** to set the next refresh time (5 minutes at minimum) for a widget. After the specified time elapsed, the **onUpdate** callback is invoked to update the widget.
14
15### Required Permissions
16
17**ohos.permission.MEDIA_LOCATION**, which allows an app to access geographical locations in the user's media file.
18
19**ohos.permission.READ_MEDIA**, which allows an app to read media files from the user's external storage.
20
21**ohos.permission.WRITE_MEDIA**, which allows an app to read media files from and write media files into the user's external storage.
22
23### Usage
24
251. When you start the app for the first time, you must grant the app the permission to access the geographical location information in your media file.
26
272. Touch and hold the app icon to create a widget and add the widget to the home screen. The widget displays images in **Gallery** properly.
28
293. Touch the image displayed on the widget to start the app.
30
31### Constraints
32
331. This sample can only be run on standard-system devices.
34
352. This sample is based on the stage model, which is supported from API version 9.
36
373. DevEco Studio 3.0 Beta3 (Build version: 3.0.0.992, built on July 6, 2022) must be used.
38
394. Before creating a widget, ensure that there are images in **Gallery**. Otherwise, the widget will not be updated.
40
415. The update takes place 5 minutes after the widget is created when the device screen is on.
42