I am creating screen recording applications. Using MediaRecorder, I need to tell its .setOutputFile() method the path to save the file. I used to take a path using the Environment.getExternalStoragePublicDirectory() method, but this method is deprecated in API 29. In the documentation I found that now for storing video files, music, you need to use MediaStore, but there I only found how to add an already created video to the gallery. Now I use the context.getExternalFilesDir() method and add the video to the gallery using this code
public void addVideo(File videoFilePath, String name) {
ContentValues values = new ContentValues(3);
values.put(MediaStore.Video.Media.TITLE, name);
values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
values.put(MediaStore.Video.Media.DATA, videoFile.getAbsolutePath());
getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
}
This code works on all api except 29. On 29 api, the video is added to the gallery, but it doesn’t work, although if you go to the folder where the video is saved and start it from there, and not from the gallery, it will work. Which way to specify the path to the .setOutputFile () method so that the video on did api 29 work fine?