0
    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?

Lev T.
  • 31
  • 3

1 Answers1

1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I tried this solution and still I'm getting: java.io.FileNotFoundException: /storage/emulated/0/Movies/.pending-1648489848-VID_20220321_175048.mp4: open failed: EACCES (Permission denied) exeption on android 12. – Lev T. Mar 21 '22 at 17:55
  • @LevT.: It looks like you are getting a temporary `Uri` for some reason, probably due to bugs in whichever camera app you are using. You might consider switching to using `EXTRA_OUTPUT` and telling the camera app where you want the video to be recorded, ensuring that it is a location that your app can use. – CommonsWare Mar 21 '22 at 17:58
  • It looks like this solution works, actually I use EXTRA_OUTPUT for photos. However now I have a strange bug on android 12 emulator (not real device) with this aproach the duration of the video is 3 hours and a half when the real duration is about 3 seconds. On android 11 in real device this aproach works like a charm. – Lev T. Mar 21 '22 at 20:55
  • 1
    I checked on a real android 12 device, it works just fine. look like a bug on android 12 emulator of android studio. CommonsWare thank you very much! – Lev T. Mar 22 '22 at 19:44