问题描述
在我们的应用程序中,有一个相机照片捕获功能,其捕获图像成功并保存在外部存储中(/storage/emulated/0/DCIM/Camera/Appname/foldername)。但它没有显示在图库中。
我们用来保存捕获图像的代码;
private void savetoPublicStorage(Bitmap bitmap,File file) {
FileOutputStream out = null;
try {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
out = getFOSForPublicCameraDirectory(file.getName());
} else {
out = new FileOutputStream(file);
}
bitmap.compress(Bitmap.CompressFormat.PNG,100,out);
} catch (IOException e) {
ExceptionLogger.logException(e);
}
private FileOutputStream getFOSForPublicCameraDirectory(String fileName) {
FileOutputStream fos = null;
ContentResolver contentResolver = getContentResolver();
Uri imageUri = getURIForPublicCameraDirectory(fileName);
try {
fos = (FileOutputStream) contentResolver.openOutputStream(imageUri);
} catch (Exception e) {
ExceptionLogger.logException(e);
}
return fos;
}
private Uri getURIForPublicCameraDirectory(String fileName) {
ContentResolver contentResolver = getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.disPLAY_NAME,fileName);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE,"image/png");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH,Environment.DIRECTORY_DCIM + File.separator + "Camera" + File.separator + "Folder1" + File.separator + "Folder2");
return contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);
}
同样的代码在三星 S20(Android 11)上工作。问题仅在于 S20。 我已经关注了 https://www.samsung.com/us/support/troubleshooting/TSG01001310/ 并检查了所有给定的场景,但没有任何帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)