Nthily
03/30/2021, 3:09 PMval getContent = registerForActivityResult(ActivityResultContracts.GetContent()) {
viewModel.imageUriState.value = it
// Handle the returned Uri
}
if (viewModel.imageUriState.value != null) {
Log.d(TAG, "${viewModel.imageUriState.value}")
}
getContent.launch("image/*")
Hi, I got the Uri of the photo from the user's album using registerForActivityResult, how can I convert the Uri to ImageBitmap and store it in my room? i've searched a lot from StackOverflow, but there doesn't seem to be a very standard answerNthily
03/30/2021, 3:12 PMScott Kruse
03/30/2021, 3:41 PMScott Kruse
03/30/2021, 3:42 PMNthily
03/30/2021, 3:42 PMNthily
03/30/2021, 3:42 PMalorma
03/30/2021, 3:47 PMIan Lake
03/30/2021, 3:49 PMGetContent
only gives you temporary access to the Uri and its contents. You'll need to create your own copy (say, in getFilesDir()
) and persist the relative path of that fileNthily
03/30/2021, 10:39 PMNthily
03/30/2021, 10:39 PMNthily
03/30/2021, 10:40 PMIan Lake
03/30/2021, 10:41 PMcopyTo
method in the Kotlin Standard library which makes it easy to connect the InputStream to an OutputStream: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/java.io.-input-stream/copy-to.htmlIan Lake
03/30/2021, 10:42 PMNthily
03/30/2021, 10:42 PMNthily
03/30/2021, 10:42 PM