保存的视频未在Android画廊中显示9
我在内部存储中存储视频,但保存的视频没有出现在画廊中。要查看首先,我必须打开文件经理,然后回到画廊。 视频
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论