I take a photo and save it to external storage :
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File photoFile = getPhotoFile();
String authorities = getActivity().getPackageName() + ".fileprovider";
imageUri = FileProvider.getUriForFile(getActivity(), authorities, photoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, 1);
It works fine
But what about recording a video
I wrote some code like this but i think it's not correct :
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
File videoFile = getVideoFile();
String authorities = getActivity().getPackageName() + ".fileprovider";
videoUri = FileProvider.getUriForFile(getActivity(), authorities, videoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
startActivityForResult(intent, 2);
What can i do?
EDIT: And these methods create a dir and return photo and video files
public File getPhotoFile() {
//create a random name
String randomName = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File mainPath = new File(path, "/Images");
if (!mainPath.exists()) {
mainPath.mkdirs();
}
File photoPath = new File(mainPath, randomName + ".jpg");
return photoPath;
}
public File getVideoFile() {
//create a random name
String randomName = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File mainPath = new File(path, "/Videos");
if (!mainPath.exists()) {
mainPath.mkdirs();
}
File photoPath = new File(mainPath, randomName + ".mp4");
return photoPath;
}