Skip to content

Selection limit to file picker #112

Answered by anggrayudi
AkshayAshokCode asked this question in Q&A
Discussion options

You must be logged in to vote

Currently, there's no Intent.EXTRA_* in Android framework to set maximum selected files. But you have 2 alternatives:

First alternative: Request again after the files are selected.

storageHelper.onFileSelected = { requestCode, files ->
    if (files.size > 4) {
        Toast.makeText(this, "Please select max 4 files", Toast.LENGTH_SHORT).show()
        storageHelper.openFilePicker(REQUEST_CODE_PICK_FILE, true)
    } else {
        // do stuff
    }
}

Second alternative: Take only as many as elements you need.

storageHelper.onFileSelected = { requestCode, files ->
    val selected = files.take(4)
}

I'll update this answer once Google added this capability via Intent.EXTRA_*

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@AkshayAshokCode
Comment options

@anggrayudi
Comment options

@AkshayAshokCode
Comment options

Answer selected by anggrayudi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants