Skip to content

fix: media scan on download for Android 11+#16726

Merged
alperozturk96 merged 2 commits intonextcloud:masterfrom
mykh-hailo:fix/media-scan-on-download
Mar 26, 2026
Merged

fix: media scan on download for Android 11+#16726
alperozturk96 merged 2 commits intonextcloud:masterfrom
mykh-hailo:fix/media-scan-on-download

Conversation

@mykh-hailo
Copy link
Contributor

@mykh-hailo mykh-hailo commented Mar 20, 2026

Summary

Ensures downloaded files are scanned and indexed so they appear in the device’s media library (e.g. Photos/Gallery) on Android 11 (API 30) and above.

Closes: #16101

Problem

In triggerMediaScan(), Android 11+ was handled by only logging "SDK > 29, skipping media scan" and not performing any scan. As a result, files downloaded via the Nextcloud app were not added to the MediaStore and did not show up in system media apps.

Solution

Use MediaScannerConnection.scanFile() for devices with SDK ≥ 30 instead of skipping the scan. This API:

Works correctly on Android 10+
Takes the file path and optional MIME type
Uses a callback for success and failure
Logs scan completion or failure for debugging

Changes

  • FileDataStorageManager.java

    • Added MediaScannerConnection import
    • Replaced the “skip” logic on Android 11+ with MediaScannerConnection.scanFile()
    • Passes the file’s MIME type when OCFile is available
    • Adds callback logging for scan success and failure

This PR was generated by Mykhailo. View the repository job log.

@mykh-hailo mykh-hailo force-pushed the fix/media-scan-on-download branch from 6c58db1 to 8a29a57 Compare March 20, 2026 21:28
@mykh-hailo
Copy link
Contributor Author

mykh-hailo commented Mar 20, 2026

@alperozturk96 I am happy for my first contribution on nextcloud-android.
I'd appreciate it if you check and leave some comments on it.

cc @tobiasKaminsky

Copy link
Collaborator

@alperozturk96 alperozturk96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thank you for the PR.

Could you clarify why we’re not using MediaScannerConnection.scanFile across all supported API levels? This approach should work consistently for all API versions we currently support.

Additionally, it would be helpful to include test coverage for this change. I suggest add the Context as a new parameter and providing an overloaded function so that existing callers do not need to be modified.

Please also consider adding a new Kotlin test class that verifies this behavior, including proper context injection for testing purposes.

@mykh-hailo mykh-hailo force-pushed the fix/media-scan-on-download branch from 2466920 to 55e6683 Compare March 24, 2026 22:19
@mykh-hailo
Copy link
Contributor Author

Hi @alperozturk96 I update my code for your comments.
I'd appreciate it if you check it and provide any feedback.
Thank you.

Signed-off-by: mykh-hailo <kristianderonta0205@gmail.com>
Signed-off-by: mykh-hailo <kristianderonta0205@gmail.com>
@mykh-hailo mykh-hailo force-pushed the fix/media-scan-on-download branch from 55e6683 to 82478f5 Compare March 25, 2026 04:03
@alperozturk96 alperozturk96 added this to the Nextcloud App 33.1.0 milestone Mar 25, 2026
@mykh-hailo
Copy link
Contributor Author

Hi @alperozturk96 , @tobiasKaminsky
Cold you possibly let me know the ETA for the merge please?

@alperozturk96 alperozturk96 merged commit 48bea3c into nextcloud:master Mar 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Downloaded images do not appear under Andorid Gallery until reboot

3 participants