Hi i have been trying to record and save a video from Nougat 7.0 using intent, I can record a video but its not getting saved in the device storage. I even used FileProvider
to avoid 'FileUriExposedException'. But when it comes for Capturing Images it is getting saved in the below specified path.
Here is my code.
private Uri imageUri;
private File imageFile = null;
public File videoFilePath() {
return new File(getDefaultCameraPath(), "Video_" + System.currentTimeMillis() + ".mp4");
}
private void callCameraIntent(){
Intent cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
imageFile = videoFilePath();
imageUri = FileProvider.getUriForFile(CreatePostActivity.this, BuildConfig.APPLICATION_ID + ".provider", imageFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, 2);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != Activity.RESULT_CANCELED) {
//Here it returns imageFile does not exist so it skips the if statement
if (resultCode == Activity.RESULT_OK && requestCode == 2 && imageFile != null && imageFile.exists()) {
}
}
}
The above code works well for all the pre-Nougat
version. Can anyone provide me a better solution to record the video and save in device storage.