Deepak Gahlot
03/04/2021, 4:24 AMDeepak Gahlot
03/04/2021, 4:24 AMval registerTakeFile = registerForActivityResult(
ActivityResultContracts.OpenDocument()
) { uri ->
File(uri.path)
if (uri != null) {
var file = File(uri.path!!).name
fileNames.value = file
} else {
fileNames.value = ""
}
}Deepak Gahlot
03/04/2021, 4:24 AM/document/msf:27Deepak Gahlot
03/04/2021, 4:25 AMIan Lake
03/04/2021, 4:34 AMContentResolver methods like openInputStream to access the file contents from the UriDeepak Gahlot
03/04/2021, 4:36 AMIan Lake
03/04/2021, 4:42 AMLocalContext.current.contentResolverephemient
03/04/2021, 4:59 AMIan Lake
03/04/2021, 5:11 AMActivityResultContracts.GetContent and GetMultipleContents already add CATEGORY_OPENABLE for you, as per the docsDeepak Gahlot
03/04/2021, 5:17 AMDeepak Gahlot
03/04/2021, 5:17 AMval registerTakeFile = registerForActivityResult(
ActivityResultContracts.OpenDocument()
) { uri ->
File(uri.path)
if (uri != null) {
var inputStream: InputStream? = null
val fileReader = ByteArray(4096)
var fileSizeDownloaded: Long = 0
inputStream = context.contentResolver.openInputStream(uri)
while (true) {
val read = inputStream!!.read(fileReader)
if (read == -1) {
break
}
fileSizeDownloaded += read
}
}
}Ian Lake
03/04/2021, 5:18 AMIan Lake
03/04/2021, 5:18 AMDeepak Gahlot
03/04/2021, 5:19 AMIan Lake
03/04/2021, 5:19 AMIan Lake
03/04/2021, 5:20 AMDeepak Gahlot
03/04/2021, 5:21 AMDeepak Gahlot
03/04/2021, 5:31 AMDeepak Gahlot
03/04/2021, 5:32 AMIan Lake
03/04/2021, 5:52 AMFile has always been the wrong abstraction for any library. InputStream or FileDescriptor was what any library should have used as inputDeepak Gahlot
03/04/2021, 5:53 AM