DownloadPermissionHandler

class DownloadPermissionHandler(permissionState: PermissionState, context: Context, onPermissionRequired: () -> Unit = { if (!context.wasPermissionRequested(permissionState.permission) || permissionState.status.shouldShowRationale) { permissionState.launchPermissionRequest() } else { context.openSystemSettings() } }, onPermissionGranted: (Map<String, Any>) -> Unit = { payload -> (payload[PayloadAttachment] as? Attachment)?.let { ChatClient .instance() .downloadAttachment(context, it) .enqueue() } }) : PermissionHandler

Default implementation of the download permission handler. By default will request the user to enable the permission and once it has been granted will download the attachment.

Parameters

permissionState

The permissionState for the permission we need. This should be Manifest.permission.WRITE_EXTERNAL_STORAGE.

context

The context for executing actions.

onPermissionRequired

Handler when the user wants to download a file but the permission has not been granted. By default it will prompt the user for the permission or take him directly to settings.

onPermissionGranted

Handler when the user grants the permission. By default will download the requested file.

Constructors

Link copied to clipboard
constructor(permissionState: PermissionState, context: Context, onPermissionRequired: () -> Unit = { if (!context.wasPermissionRequested(permissionState.permission) || permissionState.status.shouldShowRationale) { permissionState.launchPermissionRequest() } else { context.openSystemSettings() } }, onPermissionGranted: (Map<String, Any>) -> Unit = { payload -> (payload[PayloadAttachment] as? Attachment)?.let { ChatClient .instance() .downloadAttachment(context, it) .enqueue() } })

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun canHandle(permission: String): Boolean

Checks whether the permission handler can handle the given permissions.

Link copied to clipboard

Observes the change in the permission state and automatically downloads the attachment once the permission has been granted.

Link copied to clipboard
open override fun onHandleRequest(payload: Map<String, Any>)

Called to handle a request if the permission is granted, prompts the user to enable the permission otherwise.

Inherited functions

Link copied to clipboard
open fun canHandle(permissions: List<String>): Boolean

Checks whether the permission handler can handle the given permissions.