2 min read

Don't Forget to 'Media Rescan' on Android

Don't Forget to 'Media Rescan' on Android
Photo by Denny Müller / Unsplash

I had this problem situation: I have this existing folder contains my photos, let's say /sdcard/september-photos, and that folder had been synced/backup to Google Photos. Then after a while, I transferred new photos to the folder via adb tools -- tried Android File Manager on macbook, but somehow it failed to connect to my pixel, hence using adb manually --, I checked that it transferred succesfully, but Google Photos didn't show the new photos.

After a quick googling, I found out that in android, you need to do Media Rescan to update the "internal database" contains the index of all media files (e.g: photo, music, video, etc), especially if you add the files by using adb script. However, I didn't find this problem if I copied the files directly via android file manager (e.g: external sdcard is connected via usb-c and i transferred the files via android's file manager), seems like the file manager automatically does that for you.

Tried this adb command solution:

adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///sdcard

But it got me this error

Broadcasting: Intent { act=android.intent.action.MEDIA_MOUNTED dat=file:///... flg=0x400000 }

Exception occurred while executing 'broadcast':
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=10757, uid=2000
	at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:13783)
	at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:13623)
	at com.android.server.am.ActivityManagerService.broadcastIntentWithFeature(ActivityManagerService.java:14501)
	at com.android.server.am.ActivityManagerShellCommand.runSendBroadcast(ActivityManagerShellCommand.java:808)
	at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:221)
	at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
	at android.os.ShellCommand.exec(ShellCommand.java:38)
	at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:9249)
	at android.os.Binder.shellCommand(Binder.java:1049)
	at android.os.Binder.onTransact(Binder.java:877)
	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4731)
	at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2628)
	at android.os.Binder.execTransactInternal(Binder.java:1285)
	at android.os.Binder.execTransact(Binder.java:1244)

Until now, I haven't found the solution using the adb command above (if you know, please let me know in the comment).

Fortunately, there is this android app called mediaReScan:updateMediaStorage, I finally able to refresh the media databases on my folder /sdcard/september-photos. It lets you chose the folder(s) to be scanned and updated the android's "internal database".

Hope this is useful!