Media Scanner (MediaScannerConnection)
Also known as: android media scanner, media store rescan, android media scanner
Android's media scanner is the system service that indexes media files into the MediaStore database so they appear in Gallery, Photos, and content queries. Apps trigger it via MediaScannerConnection.scanFile to add or refresh entries after creating or deleting files.
- The media scanner indexes media into the MediaStore database queried via ContentResolver.
- Since Android 10, inserting into MediaStore directly is preferred over the deprecated scan broadcast.
- Deleting via ContentResolver removes both the file and its index entry, avoiding stale gallery thumbnails.
What the media scanner does
The media scanner reads image, audio, and video files on a device, extracts metadata (dimensions, duration, EXIF metadata, MIME type), and writes rows into the MediaStore database. Apps and the system Gallery then query MediaStore through ContentResolver instead of walking the file system directly.
Historically apps called MediaScannerConnection.scanFile() to ask the scanner to index a specific path, or broadcast ACTION_MEDIA_SCANNER_SCAN_FILE for a single file. The scanner also runs automatically at boot and when removable storage is mounted.
How it changed with scoped storage
Since Android 10 introduced scoped storage, the recommended way to add media is to insert directly into MediaStore via ContentResolver.insert(), which registers the file immediately without a separate scan. The legacy ACTION_MEDIA_SCANNER_SCAN_FILE broadcast is deprecated, though MediaScannerConnection.scanFile() remains for files written outside the MediaStore-managed flow.
Conversely, when a file is deleted, its MediaStore entry must be removed so it stops appearing in galleries. Deleting through ContentResolver.delete() removes both the file and its index row; deleting a raw file directly can leave a stale entry until the next scan reconciles it.
Why it matters for cleanup
A cleaner that removes duplicate or junk photos must keep MediaStore in sync, otherwise the Gallery shows ghost thumbnails for files that no longer exist, or fails to show newly freed space. Deleting via ContentResolver keeps the index correct, and a targeted rescan repairs any drift.
Cleanor deletes through the MediaStore-aware path so removed duplicate photos and large files disappear cleanly from Gallery and the index reflects real, reclaimed storage.