Send Intent to run Media Scanner

481 views
Skip to first unread message

Ganesh Shenoy

unread,
Mar 4, 2015, 4:17:47 AM3/4/15
to tas...@googlegroups.com
So I have been having trouble copying music files to my Nexus 5 using the ES File Explorer (which is the only free app I could find on the Play Store that support OTG without the need for root), trouble being that it doesn't run the Media Scanner on copied files due to which the songs show up on Google Play with track numbers missing.

Since I have just started using Tasker, I thought I would use Intents to help me. This is what I have so far, and it is not working:

Test (34)
A1: Send Intent [ 

    Action:android.intent.action.MEDIA_SCANNER_SCAN_FILE 

    Cat:None 

    Mime Type: 

    Data:file:///storage/sdcard0/Music/The Bangles/Definitive Collection - feat. Susanna Hoffs (1995)/01 Walk Like an Egyptian.mp3 

    Extra: 

    Extra: 

    Package: 

    Class: 

    Target:Broadcast Receiver ] 

There is hardly any detailed information on the MEDIA_SCANNER_SCAN_FILE intent anywhere, so I don't know if I need to specify any parameters that I am not.

Help please.

Odysseos

unread,
Mar 24, 2015, 5:02:30 AM3/24/15
to tas...@googlegroups.com
Hi Ganesh. I have a shell Command to force a Media Scan:
Run Shell command : /system/bin/am/broadcat -a android.intent.action.MEDIA_MOUNTED -d file:///storage/ExtSdCard/NewFiles
where NewFiles ia a dir where I store  taken screenshots.

Ganesh Shenoy

unread,
Mar 24, 2015, 6:02:07 AM3/24/15
to tas...@googlegroups.com
Thanks for the reply. But your method requires root. :)

Richard Wallace

unread,
Mar 24, 2015, 9:53:10 AM3/24/15
to tas...@googlegroups.com
Ive been looking for a way to force  a media scan and got excited when i found this...
Alas it does not work...
Im rooted on 4.4.2
the error i get is 127
Im guessing you have a typo there and it should say broadcast...which i have also tried, but doesnt work.

Ludovico D'Argenio

unread,
Mar 24, 2015, 10:08:38 AM3/24/15
to tas...@googlegroups.com

Yes, there are two typos... I apologize for my mistake
Here the correct script:

/system/bin/am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///storage/ExtSdCard/New

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/gzfnvw7JT-8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.
Screenshot_24-03-2015_15.04-255.png

Richard Wallace

unread,
Mar 24, 2015, 12:52:12 PM3/24/15
to tas...@googlegroups.com
Thanks
The script now runs OK.
However it doesn't seen to do anything.
I've added a folder with a new picture, ran the script and it won't show in gallery app?

Ludovico D'Argenio

unread,
Mar 24, 2015, 12:59:59 PM3/24/15
to tas...@googlegroups.com

Sometimes, (I don't know why it happens) it takes few minutes before pics are shown. Other times pics are shown soon as them were saved. Try to open and reopen several times the dir...

Abdullah Alahdal

unread,
Mar 24, 2015, 1:23:18 PM3/24/15
to tas...@googlegroups.com
Have you tried the action 'Scan Card' it is working fine with images. Maybe other media as well.

Richard Wallace

unread,
Mar 24, 2015, 1:35:51 PM3/24/15
to tas...@googlegroups.com
I've left it for 30 mins and nothing showing.

Could you elaborate abdullah?

Ludovico D'Argenio

unread,
Mar 24, 2015, 1:38:43 PM3/24/15
to tas...@googlegroups.com

Well, it sounds strange to me. Maximum time I have to wait is about 3 / 4 min. I run this script on a rooted Galaxy S5 with Stock Rom

Il 24/Mar/2015 18:35 "Richard Wallace" <richiew...@googlemail.com> ha scritto:
I've left it for 30 mins and nothing showing.

Could you elaborate abdullah?

Ludovico D'Argenio

unread,
Mar 24, 2015, 1:41:58 PM3/24/15
to tas...@googlegroups.com

Just goven a try to Scan Card action as Abdullah suggested. Same behaviour...

Abdullah Alahdal

unread,
Mar 24, 2015, 1:42:25 PM3/24/15
to tas...@googlegroups.com
I have a task that take a screen shot using shell command and at the end of the task I have the action 'Scan Card'. Immediately after the task end, I can see my gallery updated.

Below is my task.

Screenshot (128)
A1: Variable Set [ Name:%filenamepath To:/storage/emulated/0/Pictures/Screenshots/Screenshot_%TIMES.jpg Do Maths:Off Append:Off ]
A2: Run Shell [ Command:/system/bin/screencap -p %filenamepath Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]
A3: Scan Card [ File:Pictures/Screenshots/ ]
A4: Menu [ Title:Select Action Background Image: Layout:IconAndTextMenu Timeout (Seconds):30 Show Over Keyguard:On Items:(2) ]

Richard Wallace

unread,
Mar 24, 2015, 1:49:29 PM3/24/15
to tas...@googlegroups.com
Thanks.
Didn't know about the scan card action.
Works perfectly.
Cheers Abdullah!

Richard Wallace

unread,
Mar 24, 2015, 3:30:50 PM3/24/15
to tas...@googlegroups.com
Changed my mind!!!
It works with new files, but now when files are deleted
Reply all
Reply to author
Forward
0 new messages