Issue
Since startActivityForResult is deprecated I try to make the new method work.
This is how I pick a file (not tested yet because result code not ready):
intent.type = "image/*"
intent.putExtra(
Intent.EXTRA_MIME_TYPES,
arrayOf("image/png", "image/jpeg", "image/gif", "video/mp4")
)
intent.action = Intent.ACTION_GET_CONTENT
getCommentMedia.launch(intent)
and this is how I try to receive it:
val getCommentMedia = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
Log.d(tagg, "returned")
if (result.resultCode == Activity.RESULT_OK) {
selectedFileUri = result.data
}
}
I get
Type mismatch: inferred type is Intent? but Uri? was expected
on
result.data
Solution
ActivityResultContracts.StartActivityForResult()
returns an intent
as a result. To get the Uri
of the result data, call data
method on the intent. See the below code:
val getCommentMedia = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
Log.d(tagg, "returned")
if (result.resultCode == Activity.RESULT_OK) {
selectedFileUri = result.data?.data
}
}
Answered By - Alpha 1
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.