保存的视频未在Android画廊中显示9

发布于 2025-01-25 06:52:46 字数 1718 浏览 2 评论 0原文

我在内部存储中存储视频,但保存的视频没有出现在画廊中。要查看首先,我必须打开文件经理,然后回到画廊。 视频

                        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();

我使用Media Store在Android Q中存储了相同的

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

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文