I have the method below, and it works fine for the internal storage and external SD card on Android 4.3 or older:
public void Recorder_Prepare() {
recorder = new MediaRecorder();
recorder.setPreviewDisplay(holder.getSurface());
mCamera.unlock();
recorder.setCamera(mCamera);
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setProfile(camcorderProfile);
recorder.setVideoSize(ResolutionWidth, ResolutionHeight);
File DirectoryExistCheck = new File(VideoFolderAbsolutePATH);
if(!DirectoryExistCheck.exists()) {
DirectoryExistCheck.mkdir();
}
String VideoPath = VideoFolderAbsolutePATH + separator + "Video.mp4";
File NewVideoFile = new File(VideoPath);
recorder.setOutputFile(NewVideoFile.getAbsolutePath());
recorder.setVideoFrameRate(camcorderProfile.videoFrameRate);
try {
recorder.prepare();
}
catch (IllegalStateException e) {
Log.e("MyTag", "IllegalStateException : " + Log.getStackTraceString(e)); }
catch (IOException e) {
Log.e("MyTag", "IOException : " + Log.getStackTraceString(e)); }
recorder.start();
}
........
........
Now I am picking a folder using the New Storage Access Framework for Android 5.0+:
public void FolderSelection_Lollipop() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, PICK_FOLDER_CODE_Lollipop);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
if(requestCode == PICK_FOLDER_CODE_Lollipop) {
if(resultCode == RESULT_OK) {
// Get Uri from Storage Access Framework.
Uri Uri_Lollipop = resultData.getData();
VideoFolderAbsolutePATH = Uri_Lollipop.getPath();
//also tried:
VideoFolderAbsolutePATH = Uri_Lollipop.toString();
// Persist access permissions.
this.getContentResolver().takePersistableUriPermission(Uri_Lollipop,
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
}
}
The Recorder_Prepare() method no long works as it is giving me the IllegalStateException on Android 5.0+ :-(
I have also tried to follow the steps from this link:
Saving a video file with FileDesriptor
Same results...
The new SAF seems to be a mess for me although I have already tried to do my research online.
Does anyone know a work around or solution for this?
Thank you so much for your help and your kindness time.
....
Update: 6/8/16 at 10:41am
The link above actually works. It was an error with the Recorder_Prepare(), so I just moved stuff around and worked.