The mediaserver in my stock and rooted Android 6.0.1 (running in Nexus 6) doesn't detect new files created or moved to into /sdcard using adb. It doesn't detect until I do a soft/full reboot which I find unacceptable to perform.
I'm able to manually run mediaserver using command-line to begin file scanning again# and I want this to be done automatically and immediately whenever a new file is created under /sdcard.
At the moment, I have Tasker run the mediaserver whenever USB cable is unplugged.*
The obvious choice here seems to be an automation app of which I tried Tasker and Automate, and both amazingly failed to detect new files, particularly under /sdcard/Music, when created through adb. However, if an app created files in any directory under /sdcard those two apps immediately detected the changes. I also tried pushing files to /storage/emulated/0/ instead of /sdcard/ and made corresponding changes in those two apps' triggers.That step didn't benefit me.
It is to be noted that I observed this problem in stock Android 5.1.1 and a CM13 snapshot build as well.
So, how do I achieve the goal?
I'm aware of the possibility of creating an alias in the OS running in my PC which would execute a script providing a way to push the file as well as run the mediaserver.
However, it is something I would like to avoid as much as possible.
* I was using it but later switched to a script executed from PC using an alias. However, I do not want to depend upon any of the two methods. My fingers are comfortable with typing adb push instead of adb_push or some other but single word.
- I do not intend to restrict myself to a particular directory, such as Download and neither pushing files into the latter actually works.
- I would like to stress that I'm not asking for how to run mediaserver. That I already know. All I'm looking for is: Whenever I do
adb push FILE /sdcard/FILEthe mediaserver should automatically and immediately kick in and scans the file. Regardless of any perceivable performance issue, I want it to kick in every single time.
Okay, I may be using an incorrect term. Perhaps mediaserver and media scanner are terms for two different things in Android. In the case of confusion, please stick with "media scanner" for both the current revision and the bounty note.
# Courtesy of androidyue for this helpful resource, any of the following command in preformatted text is what I can use in my device to make media scanner scan the file.
# FILE_PATH refers to the location of pushed file in Android. E.g. /sdcard/Music/lolcat.mp3 am broadcast -a android.intent.action.BOOT_COMPLETED -n com.android.providers.media/.MediaScannerReceiver am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file://FILE_PATH # guaranteed to work. See https://goo.gl/lH0CLT for proof. am broadcast -a android.intent.action.MEDIA_MOUNTED -d file://FILE_PATH
04-07 09:38:14.771 3383 3383 I MTPService: Watching /storage/emulated/0
I later pushed a sound file into /storage/emulated/0/ and nothing showed up in my music player. Logcat also didn't display anything useful either.
By the way, this app uses FileObserver, so I'm not surprised if it couldn't detect files created using adb, since it is the same issue with the automation apps I tried.
Note: Please post an answer only when you've tested it yourself. Thank you!