Sample Header Ad - 728x90

Manually trigger MediaScanner to scan files on Internal Storage on Nougat/Oreo

3 votes
1 answer
8641 views
I often manage my files in Termux with scripts that use the mv command to move or rename them. I want to manually trigger MediaProvider to scan my internal stroage (/storage/emulated/0) or a given directory in it with command line, on a phone running Nougat or Oreo. When I use a GUI file manager application, all moves/renames are immediately reflected in other MediaScanner-dependent apps like Gallery, but changes done in a terminal don't, until a reboot. So I have to manually call MediaScanner to update my changes in the filesystem. Before KitKat, this worked well on /storage/sdcard0 (a separate partition named glow): am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard The above command doesn't work now (/storage/emulated/0), obviously. I also tried this, but it doesn't seem to be working, either. am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard Just tested the commands again, they seem to be working on removable storage like /storage/sdcard1, /storage/usba or /storage/{volume id} (it gets re-scanned), but not my phone's internal (where /sdcard points to, or /storage/emulated/0). Anyone have some insights? Rebooting my phone always causes a rescan but that's inconvenient in some cases. Note: the commands are run as root, so no concerns about permissions.
Asked by iBug (7977 rep)
Jul 28, 2018, 06:19 PM
Last activity: Sep 28, 2020, 04:56 AM