为何文件选择器Downloads显示已删除文件历史,实际文件仅在设备目录可见?
Hey there, let's break down what's happening and how to fix this frustrating file picker quirk:
Why This Happens
The Downloads (with an 's') option in your file picker is actually the system's cached download history—it tracks every file you've ever downloaded, even after you delete them from your device. That's why you're seeing those dead, non-existent file entries. On the flip side, the Galaxy S6 edge > Download folder is a direct path to your device's real download directory, so it only shows files that currently exist on your phone.
Solutions to Try
1. Directly Open the Real Download Directory (Best Fix)
Skip the problematic historical "Downloads" tab entirely by forcing the file picker to open directly to your device's actual Download folder. Use the EXTRA_INITIAL_URI extra in your intent to set the starting path:
// Kotlin example val downloadDirectoryUri = MediaStore.Downloads.EXTERNAL_CONTENT_URI val openFileIntent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply { addCategory(Intent.CATEGORY_OPENABLE) type = "*/*" // Adjust to specific file types if needed (e.g., "audio/*") putExtra(DocumentsContract.EXTRA_INITIAL_URI, downloadDirectoryUri) } startActivityForResult(openFileIntent, YOUR_REQUEST_CODE)
For Java, the logic is identical—just adjust the syntax:
// Java example Uri downloadDirectoryUri = MediaStore.Downloads.EXTERNAL_CONTENT_URI; Intent openFileIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); openFileIntent.addCategory(Intent.CATEGORY_OPENABLE); openFileIntent.setType("*/*"); openFileIntent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, downloadDirectoryUri); startActivityForResult(openFileIntent, YOUR_REQUEST_CODE);
2. Validate Files After Selection (If You Need the Default Menu)
If you want to keep the full file picker menu but avoid users selecting dead files, add a check to verify the file still exists after selection:
// Kotlin example in onActivityResult override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == YOUR_REQUEST_CODE && resultCode == RESULT_OK) { data?.data?.let { fileUri -> try { contentResolver.openInputStream(fileUri)?.use { // File exists—proceed with your logic } ?: run { Toast.makeText(this, "Oops, this file no longer exists!", Toast.LENGTH_SHORT).show() } } catch (e: FileNotFoundException) { Toast.makeText(this, "Oops, this file no longer exists!", Toast.LENGTH_SHORT).show() } } } }
3. Clear System Cache (User-Facing Fix)
If you want to suggest a manual fix for users seeing outdated entries, tell them to:
- Go to Settings > Apps
- Find their default file manager app (like "My Files" or "Files")
- Tap Storage > Clear Cache
This wipes the outdated download history, though it's a one-time fix and can't be controlled via code.
Final Note
Option 1 is the most reliable—it ensures users always land in the real download folder with active files, eliminating confusion with historical entries altogether.
内容的提问来源于stack exchange,提问作者Shawn

