Reputation: 41
Intent(MediaStore.ACTION_VIDEO_CAPTURE).also { takeVideoIntent ->
takeVideoIntent.resolveActivity(packageManager)?.also {
startActivityForResult(takeVideoIntent, REQUEST_TAKE_VIDEO)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_TAKE_VIDEO && resultCode == RESULT_OK) {
var videoUri = data?.data
val intent = Intent(this, AddActivity::class.java)
intent.putExtra(VIDEO_URI, videoUri);
startActivity(intent)
}
}
In the second Activity when I try to open the uri of the video in videoview I'm Getting this exeption:
java.io.FileNotFoundException: /storage/emulated/0/Movies/.pending-1648411601-VID_20220320_200641.mp4: open failed: EACCES (Permission denied)
I found a solution that solves the problem: adding to menifest MANAGE_EXTERNAL_STORAGE permission
But google play doesn't accept my app with this permission.
What are the alternatives if any?
Upvotes: 0
Views: 754
Reputation: 1007359
Ideally, this would be one activity, not two, using fragments or composables for the individual screens.
However, if you absolutely need to get the Uri
to another activity in your app:
Attach it to the Intent
you use to start that other activity via setData()
Add Intent.FLAG_GRANT_READ_URI_PERMISSION
to the Intent
val intent = Intent(this, AddActivity::class.java)
.setData(videoUri)
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
AddActivity
would call getData()
on the Intent
to retrieve the Uri
.
Without this approach, AddActivity
has no rights to access the content.
Upvotes: 1