For the complete documentation index, see llms.txt. This page is also available as Markdown.

Permissions

Provides functions to query and request device permissions (clipboard, contacts, album, camera, microphone, location) and permission error classes.

API List

API
Description

getPermission

Checks the current status of a permission

requestPermission

Requests a permission and returns the result

openPermissionDialog

Opens the permission settings dialog

Seven permission error classes (OpenCameraPermissionError and more are also provided — when a permission-required API is denied, instances of these classes are thrown.

withPermission

Feature description

Wraps a function that requires permission. When you call the wrapped function, it first requests that permission, and if denied, errorClassit throws the error passed to errorClass, and if allowed, it executes the original function.

The returned function also has getPermission()to query the same permission, and openPermissionDialog()attached as static methods. Inside the framework, Clipboard.getText, Device.getPhotos the same API is built with this function, so Clipboard.getText.getPermission() you can check permissions in this form.

Type

Params

function withPermission<T extends (...args: any[]) => any>(
  fn: T, // Function to run after permission is allowed
  name: PermissionName, // Name of the permission to request
  access: PermissionAccess, // Type of access to request
  errorClass: new () => PermissionErrorType, // Error class to throw if permission is denied
): PermissionFunctionWithDialog<T>;

Response

Error

Code
Description

errorClassThe error passed to

when the permission request result is denieddenied.

Example code

PermissionError

Feature description

This is the common parent class of permission errors. When handling multiple permission errors at once, error instanceof PermissionErrorYou can check it with nameis `${methodName} permission error` format.

Type

Params

Response

Example code

GetClipboardTextPermissionError

Feature description

This error occurs when clipboard read permission is denied. error instanceof GetClipboardTextPermissionErrorYou can check it with PermissionErrorextends it.

Type

Example code

SetClipboardTextPermissionError

Feature description

This error occurs when clipboard write permission is denied. error instanceof SetClipboardTextPermissionErrorYou can check it with PermissionErrorextends it.

Type

Example code

FetchContactsPermissionError

Feature description

This error occurs when contacts permission is denied. error instanceof FetchContactsPermissionErrorYou can check it with PermissionErrorextends it.

Type

Example code

FetchAlbumPhotosPermissionError

Feature description

This error occurs when album permission is denied. error instanceof FetchAlbumPhotosPermissionErrorYou can check it with PermissionErrorextends it.

Type

Example code

GetCurrentLocationPermissionError

Feature description

This error occurs when location permission is denied. error instanceof GetCurrentLocationPermissionErrorYou can check it with PermissionErrorextends it.

Type

Example code

StartUpdateLocationPermissionError

Feature description

This error occurs when location update permission is denied. GetCurrentLocationPermissionErrorbecause it is an alias referring to the same class as error instanceof StartUpdateLocationPermissionErroris GetCurrentLocationPermissionError also in the instance true.

Type

Example code

OpenCameraPermissionError

Feature description

This error occurs when camera permission is denied. error instanceof OpenCameraPermissionErrorYou can check it with PermissionErrorextends it.

Type

Example code

PermissionName

Feature description

This is the name type that identifies a permission.

Type

PermissionAccess

Feature description

This is the access-type for a permission. read/writeis used for permissions where read/write are separated, such as clipboard, contacts, and album, accessis used for permissions without separate access types, such as location, camera, and microphone.

Type

PermissionStatus

Feature description

This is the status type of a permission. notDeterminedmeans the user has not yet responded to the permission request.

Type

PermissionFunctionName

Feature description

This is the function-name type where permission errors occur. PermissionErrorof nameUsed when composing

Type

PermissionErrorConstructorParams

Feature description

PermissionError This is the parameter type passed to the constructor.

Type

PermissionErrorType

Feature description

withPermissionof errorClass This is the shape of the error instance created by the parameters.

Type

GetPermissionFunction

Feature description

withPermissionAttached to a function wrapped with getPermission This is the signature of the static method.

Type

PermissionDialogFunction

Feature description

withPermissionAttached to a function wrapped with openPermissionDialog This is the signature of the static method.

Type

PermissionFunctionWithDialog

Feature description

withPermissionThis is the type of function returned by this. It adds getPermission/openPermissionDialog static methods to the original function signature.

Type

Was this helpful?