Whenever I capture a vide and I'm taken to the next screen which is the OK/Retake screen and I try to play the video; it crashes. I think this is because of the parameter (MediaStore.EXTRA_OUTPUT)
where I specify my custom path. However; if I don't pass this parameter and allow the video to be stored in the default location; the app does not crash on play button press.
Below is my code:
private void dispatchTakeVideoIntent() {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
takeVideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 100);
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
mVideoCaptureUri = mActivity.getExternalCacheDir() +
"/", ".mp4"
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mVideoCaptureUri);
takeVideoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
if (takeVideoIntent.resolveActivity(mActivity.getPackageManager()) != null) {
mActivity.startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
}
Crash log: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.example.test/cache/1517905670437.mp4 exposed beyond app through Intent.getData()