Package-level declarations
Media scanner. Fetch local and backend media.
Scanner
The scanner is a component for retrieving local and backend media. It is represented by the MediaScanner interface.
val photoManager: PhotoManager
val mediaScanner: MediaScanner = photoManager.mediaScannerMany components depend on the scanner's operation, such as Uploader.
Local Scan
The local scanner searches all local media on the device. Its operation depends on the presence of local permissions. The local scanner only scans active catalogs.
val mediaScanner: MediaScanner
// Changes the scanner's state depending on the availability of permissions. Must be called when granting permissions.
mediaScanner.recheckPermissions()
// If the scanLocal method was called earlier, it will return the same job.
val job: Deferred<Unit> = mediaScanner.scanLocal()
// Monitoring the scanner status
lifecycleScope.launch(Dispatchers.IO) {
mediaScanner.localScanStateFlow.collect { state -> // state: LocalMediaScanState
// Handle it...
}
}The local scanner uses the LocalMediaScanner logging tag.
LocalMediaScanner : [CL] [Ph] [Scanner] [Local] [PHOTO] New chunk read! Elapsed time - 00h:00m:25s:692mi
Chunk items - 500 [Update not required - 0; Inserted - 500; Updated - 0; Failed - 0]
Transaction count - 2
Transactions times: total - 00h:00m:01s:257mi; average - 00h:00m:00s:628mi; min - 00h:00m:00s:550mi; max - 00h:00m:00s:707mi.Backend Scan
The backend scanner searches all backend media for a specific user.
val mediaScanner: MediaScanner
// If the scanLocal method was called earlier, it will return the same job.
val job: Deferred<Unit> = mediaScanner.scanBackend(userId = 0L)
// Monitoring the scanner status
lifecycleScope.launch(Dispatchers.IO) {
mediaScanner.createUserIdToBackendMediaScannerStateFlow().collect { state ->
// state: Map<Long, BackendMediaScanState>
// Handle it...
}
}Logging
The backend scanner uses the BackendMediaScanner logging tag.
BackendMediaScanner : [CL] [Ph] [Scanner] [Backend] [MEDIA] [FULL] New chunk read! Chunk items - 500 [images - 340; video - 160].
Update not required - 0; Inserted - 500; Updated - 0; Failed - 0.
Transaction count - 2
Transactions times: total - 00h:00m:00s:382mi; average - 00h:00m:00s:191mi; min - 00h:00m:00s:126mi; max - 00h:00m:00s:126mi.
Elapsed time - 00h:00m:03s:442miImportant! The backend scanner first scans the entire gallery for the specified user (including the recycle bin). After a full scan, the scanner performs an incremental scan. An incremental scan retrieves only media that has changed since the last scan.
BackendMediaScanner : [CL] [Ph] [Scanner] [Backend] [MEDIA] [FULL]
BackendMediaScanner : [CL] [Ph] [Scanner] [Backend] [MEDIA] [INC]Scan Worker
The scanner launches in the background when the gallery changes, provided the autoloader is active. The following code example demonstrates notification customization.
val mediaScanner: MediaScanner
mediaScanner.scanNotificationProvider = object : ScanNotificationProvider {
override fun getNotification(): Notification {
TODO()
}
override fun getNotificationId(): Int {
TODO()
}
}