我正在使用下载管理器下载文件,如下所示:
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);
}
我将看到在图库中创建的文件夹,但该文件始终显示为已损坏。任何人都可以帮忙吗?