• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Functions
2<!--Kit: Media Library Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @yixiaoff-->
5<!--SE: @liweilu1-->
6<!--TSE: @xchaosioda-->
7
8> **NOTE**
9>
10> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
11
12## Modules to Import
13
14```ts
15import { photoAccessHelper } from '@kit.MediaLibraryKit';
16```
17
18## photoAccessHelper.getPhotoAccessHelper
19
20getPhotoAccessHelper(context: Context): PhotoAccessHelper
21
22Obtains a PhotoAccessHelper instance for accessing and modifying media files in the album.
23
24**Model restriction**: This API can be used only in the stage model.
25
26**Atomic service API**: This API can be used in atomic services since API version 11.
27
28**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
29
30**Parameters**
31
32| Name | Type   | Mandatory| Description                      |
33| ------- | ------- | ---- | -------------------------- |
34| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes  | Context of the ability instance.|
35
36**Return value**
37
38| Type                           | Description   |
39| ----------------------------- | :---- |
40| [PhotoAccessHelper](arkts-apis-photoAccessHelper-PhotoAccessHelper.md) | PhotoAccessHelper instance obtained.|
41
42**Error codes**
43
44For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
45
46| ID| Error Message|
47| -------- | ---------------------------------------- |
48| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
49
50**Example**
51
52```ts
53// The phAccessHelper instance obtained is a global object. It is used by default in subsequent operations. If the code snippet is not added, an error will be reported indicating that phAccessHelper is not defined.
54// Obtain the context from the component and ensure that the return value of this.getUiContext().getHostContext() is UIAbilityContext.
55import { common } from '@kit.AbilityKit';
56
57@Entry
58@Component
59struct Index {
60  build() {
61    Row() {
62      Button("example").onClick(async () => {
63        let context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext;
64        let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
65      }).width('100%')
66    }
67    .height('90%')
68  }
69}
70```
71