I want to record a video, store it in internal storage and access the file.
FileProvider creates an URI for the camera intent to record a video:
File path = new File(this.getFilesDir(), "shared");
File file = new File(path, UUID.randomUUID().toString() + ".mp4");
// Store URI as property of activity
this.uri = FileProvider.getUriForFile(App.getInstance().getApplicationContext(), App.getInstance().getApplicationContext().getPackageName() + ".provider", file);
Intent videoCaptureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
videoCaptureIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationLimit);
videoCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(videoCaptureIntent, REQUEST_VIDEO_CAPTURE);
The video file is stored in the internal storage of the app, I can see the file in Android File Explorer in the correct location.
However, I cannot access the file afterwards, the file cannot be found. The uri
property still shows the correct uriString
and authority
.
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_VIDEO_CAPTURE) {
File file = new File(this.uri.getPath());
Log.d(file.exists()); // Logs false
}
Why is that?