Functions
NOTE
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.
Modules to Import
import { photoAccessHelper } from '@kit.MediaLibraryKit';
photoAccessHelper.getPhotoAccessHelper
getPhotoAccessHelper(context: Context): PhotoAccessHelper
Obtains a PhotoAccessHelper instance for accessing and modifying media files in the album.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| context | Context | Yes | Context of the ability instance. |
Return value
| Type | Description |
|---|---|
| PhotoAccessHelper | PhotoAccessHelper instance obtained. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
// 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.
// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
import { common } from '@kit.AbilityKit';
@Entry
@Component
struct Index {
build() {
Row() {
Button("example").onClick(async () => {
let context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
}).width('100%')
}
.height('90%')
}
}