Saved video not showing in gallery android 9

133 views Asked by At

I am storing video in internal storage but the saved video is not showing up in gallery. To see that first i have to open my file manager then come back to gallery. I stored the same video in android Q using media store but in

                        ContentResolver contentResolver = getContentResolver();
                        ContentValues contentValues = new ContentValues();
                        contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "videoFileName");
                        contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "video/mp4");
                        contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_MOVIES);
                        Uri finalUriPath = contentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentValues);
                        File sourceLocation = new File(finalUri.getPath());
                    
                        InputStream in = new FileInputStream(sourceLocation);
                        FileOutputStream out = new FileOutputStream(String.valueOf(finalUriPath));
                        byte[] buf = new byte[1024];
                        int len;
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        out.close();
                        contentValues.clear();
                        contentValues.put(MediaStore.Video.Media.IS_PENDING, 0);

                        StatusShowerActivity.this.getContentResolver().update(finalUriPath, contentValues, null, null);
                        Toast.makeText(StatusShowerActivity.this, "Saved", Toast.LENGTH_SHORT).show();

Exception got from Catch in android 9

 java.io.FileNotFoundException: null (Read-only file system)
0

There are 0 answers