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()
}
})