Xposed Media Scanner Optimizer

Let me introduce my new Xposed Module. It allows you to customize the way the media scanner works on Android.
It solves several problems that I have with the media scanner. As Xposed module developer one needs to reboot the device quite often. The media scanner runs on each reboot and eating much battery as the device stays awake while the scanner is running and doing lots of I/O.
For non developer the Xposed Media Scanner Optimizer also provides useful functionality.

First of all let me explain how the media scanner works on Android. Each time the device has bootet it runs and scans all volumes/storage. Depending on the size of the storage available on the device and the SD Card and the number of files this usually takes between 5 and 20 minutes. For each file and directory it finds it creates an entry in the so-called Android Media Store. For special file types like images, videos and music files it also scans for meta data like EXIF information for images and mp3 tags for music files. Applications may query the Media Store to find specific files bases on the file type or meta data. Well known applications that do so are the Gallery and the Music Player. Other applications may also do so.
The media scanner runs as a background service and is not visible to the user.

The Xposed Media Scanner Optimizer provides the following tweaks to the media scanner:

  • The service can be run as a foreground service allowing the user to see when and how long it runs. Foregound services are visible to the user via a notification.
  • When the scanner has finished details of how long each scan took are shown using a notification.
  • The scanner can be run in a mode where only specific directories will be scanned. This reduces scan times and thus saves battery. It also allows you to control what shows up in the Gallery or Music Player apps.
  • It is possible to tell the scanner that only specific file types (e.g. music files) should be scanned on a directory basis.
  • It is possible to prevent automatic scanning for the external volume. Only triggering the scanner form within the XMSO app will cause the media scanner to run.
  • It allows you to completely delete the contents of the media store.
  • It allows you to trigger a scan whenever you want to

On some Android phones the scanner is scheduled to run several times after a boot which is completely unnecessary and in my opinion is a bug. These repetitive scans can be prevented.
All files that will not be scanned will not show up in the Gallery or Music Player. I for myself use this feature to restrict what is shown in the Music Player for example. I only want to see music files from specific directories on my SD card to show up in the music player.
The directories that contain my music files also contain images for the album and the artist. These files would normally show up in the Gallery. There, I only want to see the contents of the directories where I keep my pictures. I don't want to have the gallery cluttered with album artwork or images of artists from the music directories.

The Xposed Media Scanner Optimizer settings application can be started from the launcher and allows you to configure the following settings:

  • Repetitive Scans: If this preference is checked repetitive scans at boot time will be prevented. Repetitive scans are not necessary and only cause greater battery drain. Depending on the Android version and vendor repetitive scans may occur and can be prevented by checking this preference.
    Service Importance: When checked the media scanner will run as foreground service and its operation will be visible to the user via a notification.
  • Thread Priority: If checked the media scanner will be forced to run with background thread priority even if it is running as a foreground service. This is the suggested setting. If unchecked the thread priority depends on whether it runs as a foreground service or not.
  • Directories: If checked the media scanner will only scan directories that have a .scanMedia file (i.e. an empty file with a dot as first part of the name similar to the .noMedia file). Use a file explorer app to create this file. This file can be placed in a directory that may contain subdirectories. The subdirectories will be scanned as well. If unchecked all directories will be scanned (except for the ones containing a .noMedia file - this default behavior of the media scanner is not altered by the Xposed Media Scanner Optimizer).
  • Media Types: If checked only certain file types will be scanned. To define which file types the scanner will scan in a directory create the following files: .scanMusic, .scanVideo and .scanPictures. So for a directory containing a collection of music albums you would need to create a .scanMusic file at the directory that contains all albums if you only want the music files scanned. Images contained in the album directories would then be skipped.
  • Run automatically: If checked the media scanner will scan whenever it is told to do so by the system. If unchecked it only scans the external volume when triggered from the XMSO app. Requests for the scanning of single files still work in either case.
  • Result Notifications: If checked a notification will be shown when the scanner has finished including information about the scan time.
  • Trigger Media Scanner: When touched a media scanner is triggered.
  • Delete Media Store Contents: When touched the contents of the media store are deleted. This will not delete the actual files on the storage. Trigger a scan or reboot to let the scanner populate the media store after deleting its contents. This is useful if the media stores already contains entries that you do not want like images from all directories in the Gallery. First check the preferences to restrict what will be scanned, empty the media store and trigger a rescan. After the rescan only what has been scanned depending on your preferences will appear in the Gallery.
  • Android Logging: If this preference is checked details of the media scanner and the Xposed module are written to the Android log. This is useful for development and to troubleshoot. For end users this should stay unchecked.
  • Xposed Log: If this preference is checked details will be written to the Xposed log. Since the Xposed log is persisted this is also useful for troubleshooting. For end users this should stay unchecked.
  • Depending on the number of files on your storage media scan times can be reduced significantly.

It should work on Android 4.1.2 (API 16) and up.

If you like the module feel free to donate :)

Author(s): 
Package: 
com.thomashofmann.xposed.mediascanneroptimizer
Version name: 
1.4.0
Release type: 
Experimental (high risk of bugs)
Number of downloads: 
20,044 in total · 4 in the last 24 hours
MD5 checksum: 
2d689a1445fac7e2bee927719a3572b2
Uploaded on: 
Friday, January 9, 2015 - 21:17
Changes: 

- Support for API Level 4 so it should work on Gingerbread ROMs
- Restructured Preferences UI

Version name: 
1.3.7
Release type: 
Stable (low risk of bugs)
Number of downloads: 
42,617 in total · 11 in the last 24 hours
MD5 checksum: 
c9fb605403d61d90b018e8f7453557b8
Uploaded on: 
Saturday, December 27, 2014 - 18:59
Changes: 

- Fix for triggering the media scanner (broken in 1.3.6)

Version name: 
1.3.6
Release type: 
Experimental (high risk of bugs)
Number of downloads: 
1,114 in total · 1 in the last 24 hours
MD5 checksum: 
d95b95e80d2ae5b1005b82bf169ed2f4
Uploaded on: 
Friday, December 26, 2014 - 12:33
Changes: 

- Workaround for Xposed framework having problems with the theming engine on CM11 based ROMs. You shoul now be able to turn on Foreground service and result notifications on CM11 based ROMs. The media scanner process might still crash once - please report back with logcat.
- Fix for a crash that would occur when scanning was restricted to certain directories and there wasn't a single directory marked for scanning using the .scanMedia marker file.
- Option to turn of donation actions in the result notifications.
- Removed donation intent from the result notification.

Version name: 
1.3.4
Release type: 
Experimental (high risk of bugs)
Number of downloads: 
2,814 in total · 0 in the last 24 hours
MD5 checksum: 
8dc61c279ed7310ad915e906f4681c25
Uploaded on: 
Monday, December 1, 2014 - 17:59
Changes: 

- Improved performance. By default XMSO will only look in top-level directories for .scanMedia files to decide which directories to scan (when restricting to certain directories). The "Performance" preference in XMSO settings app lets you change that to scan 2 levels deep in case you want to.
- More logging to find problems: You can now enable Xposed Log Debug and Xposed Log Verbose modes. Debug gives more details and verbose even more. Only turn on if asked to troubledshoot.

Version name: 
1.3.3
Release type: 
Experimental (high risk of bugs)
Number of downloads: 
629 in total · 0 in the last 24 hours
MD5 checksum: 
86bd2c44ace27784da1145e9762a37d2
Uploaded on: 
Sunday, November 30, 2014 - 12:24
Changes: 

- Fixes for @fastcx on HTC M7 ROM

Version name: 
1.3.2
Release type: 
Experimental (high risk of bugs)
Number of downloads: 
490 in total · 0 in the last 24 hours
MD5 checksum: 
0a7da2739be05f1343594ee6f375e17b
Uploaded on: 
Saturday, November 29, 2014 - 19:19
Changes: 

- One more fix for HTC ROMs
- Added more verbose logging trying to find what causes FCs for some users

Version name: 
1.3.1
Release type: 
Experimental (high risk of bugs)
Number of downloads: 
663 in total · 0 in the last 24 hours
MD5 checksum: 
7d393414726095a86bccaeeed3e05db0
Uploaded on: 
Friday, November 28, 2014 - 11:40
Changes: 

- Support for HTC specifics
- Hoping to fix some FCs on some ROMs

Version name: 
1.3
Release type: 
Stable (low risk of bugs)
Number of downloads: 
10,119 in total · 1 in the last 24 hours
MD5 checksum: 
90115addb40c7223e64fde06eb06e5af
Uploaded on: 
Tuesday, November 25, 2014 - 12:14
Changes: 

-Fixed a NullPointerException
-New feature: Disable automatic scanning of the external volume

Version name: 
1.2.1
Release type: 
Stable (low risk of bugs)
Number of downloads: 
2,067 in total · 1 in the last 24 hours
MD5 checksum: 
75874b6e9adb4b839cf674f1382bdc5f
Uploaded on: 
Monday, November 24, 2014 - 13:52
Changes: 

Fixed bug that triggering media scan and deleting media store only works once

Version name: 
1.1.3
Release type: 
Stable (low risk of bugs)
Number of downloads: 
4,322 in total · 1 in the last 24 hours
MD5 checksum: 
90c02e53f2c00ba2eb47b4b4c77ec4b0
Uploaded on: 
Tuesday, November 18, 2014 - 23:32
Changes: 

-Fixed a bug where .scanMedia files would only be found and applied in top-level folders
-Fixed a bug where apps calling the media scanner to request a scan for a file would lead to the situation that the file would appear in the Gallery although it was in a folder that should not have been scanned
-Made a change hoping to fix problems with custom Kitkat ROMs

Version name: 
1.1.2
Release type: 
Stable (low risk of bugs)
Number of downloads: 
2,595 in total · 0 in the last 24 hours
MD5 checksum: 
acf372ddcbf6c9043ae8d3b2bea3e7ae
Uploaded on: 
Monday, November 17, 2014 - 23:44
Changes: 

Fixes for CM-based ROMs and less verbose logging.

Version name: 
1.0
Release type: 
Stable (low risk of bugs)
Number of downloads: 
785 in total · 0 in the last 24 hours
MD5 checksum: 
25a77f5b1b0edd01cc02506b3abd7e89
Uploaded on: 
Monday, November 17, 2014 - 08:03
Changes: 

Initial Version