5

I'm currently using Content URIs on my file provider to retrieve camera images returned by a ACTION_IMAGE_CAPTURE intent. This works fine.

For some strange reason, the same call doesn't work when attempting to retrieve a video file from the camera.

        destinationFile = File.createTempFile("video", ".mp4", this.getFilesDir());
        Uri uri = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", destinationFile);

        Intent cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        cameraIntent.setClipData(ClipData.newRawUri(null, uri));
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(cameraIntent, ID);

When the intent returns in onActivityResult() the destinationFile is empty.

Simply replacing MediaStore.ACTION_VIDEO_CAPTURE by MediaStore.ACTION_IMAGE_CAPTURE gives me the expected behavior: The captured image is saved in destinationFile.

This happens on stock Android 6.0.1 on a Nexus device and the default Google camera app.

Are content URIs really not supported for video capture? I'd prefer rather not to use a file URI in a publicly accessible directory.

silly
  • 7,789
  • 2
  • 24
  • 37
limmatplatz
  • 268
  • 2
  • 8

1 Answers1

4

You have two separate issues: the behavior of the Google camera app and behavior across the whole Android ecosystem.

With respect to the Google camera app, we reported this as a bug with respect to Android N, since there you have no choice but to use a content Uri (if your targetSdkVersion is N or higher). It should be fixed in upcoming releases.

That being said, I would not be the least bit surprised if other camera apps encounter problems with content Uri values. This is one of the concerns that I have with Android N effectively banning the file scheme, as we are going to run into situations where neither file nor content are reliable, and we have no good way of detecting these cases.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • *offtopic* you have deleted your last answer to my question (FINGERPRINT SERVICE) please redo it - you were right! just needed to do invalidate caches after!! please redo so I can accept you – Evgeniy Mishustin Jun 09 '16 at 14:15
  • So for the time being we have to continue using file URIs - unless targeting Android N. Thanks for the clarification! – limmatplatz Jun 09 '16 at 14:39
  • 1
    @limmatplatz: "have to" is a strong term. Certainly, for your testing (and sanity), you will need to stick to `file` until your Google Camera app supports `content` properly, after which you can switch to it and test it. However, you might want to take this opportunity to determine what you are going to do when other camera apps fail to handle `content` properly. Until your `targetSdkVersion` reaches `N`, `file` should be safe and should be fairly universally supported. Hopefully you can hold off on raising `targetSdkVersion` for a while. Like, say, a decade or so. :-) – CommonsWare Jun 09 '16 at 14:44