Я использую менеджер загрузок для загрузки файла следующим образом:
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setTitle(createTitle());
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalFilesDir(activity, Environment.DIRECTORY_DOWNLOADS, subFolders + createFileName());
request.allowScanningByMediaScanner();
После загрузки я добавляю его в медиа-магазин примерно так:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ContentValues contentValues = new ContentValues();
ContentResolver database = activity.getContentResolver();
contentValues.put(MediaStore.Downloads.DISPLAY_NAME, displayName);
contentValues.put(MediaStore.Downloads.MIME_TYPE, mimeType);
contentValues.put(MediaStore.Downloads.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS + "/subfolder");
database.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues);
}
Я буду увидеть папку, созданную в галерее, но файл всегда отображается как поврежденный. Кто-нибудь может помочь?