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.
/data, or rather the internal SD?) – might be worth a try to broadcast storage mounted (take the internal SD then). Didn't say unmount/mount, just broadcasting. – Izzy Aug 27 '18 at 05:39/sdcardwhich points to/storage/emulated/0because I find that it behaves differently between/storage/emulated/0and/storage/sdcard1//storage/usba. – iBug Aug 27 '18 at 07:15mount). Might need root powers, though, as it could be "protected". – Izzy Aug 27 '18 at 08:47