Chat / Android
Chat Android v4
Chat Android
Chat
Android
Home
/
Chat
/
Android
/
Message
This is the new Docs for Chat SDK v4 for Android. To see the previous Docs, click here.

Track file upload progress using a handler

If needed, you can track the progress of file upload by passing FileMessageWithProgressHandler as an argument to a parameter when calling the sendFileMessage() method.

val params = FileMessageCreateParams(FILE).apply {
    fileName = FILE_NAME
    data = DATA
    customType = CUSTOM_TYPE
}

val fileMessage = channel.sendFileMessage(
    params,
    object : FileMessageWithProgressHandler {
        override fun onProgress(bytesSent: Int, totalBytesSent: Int, totalBytesToSend: Int) {
            val percent = (totalBytesSent * 100) / totalBytesToSend
        }

        override fun onResult(message: FileMessage?, e: SendbirdException?) {
            if (e != null) {
                // Handle error.
            }

            // You can handle actions relevant to the sent file message.
            // ...
        }
    }
)