1. Performing a scanMediascanner is only executed when the system is powered on, other scenarios require manual scanning (shooting, downloading, etc.).
A manual scan is performed by sending a Mediascanner broadcast:
1.1 Scan the specified file:
Intent.action_media_scanner_scan_file
1.2 Scan The specified directory:
"Android.intent.action.MEDIA_SCANNER_SCAN_DIR"
<span style= "FONT-SIZE:14PX;" >sendbroadcast (New Intent (Intent.action_media_scanner_scan_file, Uri.fromfile (new FILE)); Sendbroadcast ( Intent ("Android.intent.action.MEDIA_SCANNER_SCAN_DIR", Uri. ( File (dir)));</span>
2. Monitoring Scan2.1 Start scanning:intent.action_media_scanner_started
2.2 Scan Complete:
Intent.action_media_scanner_finished
<span style= "FONT-SIZE:14PX;" >intentfilter filter = new Intentfilter (); filter.addaction (intent.action_media_scanner_finished); Filter.addaction (intent.action_media_scanner_started); Registerreceiver (receiver, filter);</span>
3. Monitoring SDcard
| The SD card is plugged in and is already mounted |
intent.action_media_mounted |
| SD card exists, but not mounted |
intent.action_media_unmounted |
| SD card removed |
Intent.action_media_removed |
| SD card is shared as USB mass storage, mount is lifted |
Intent.action_media_shared |
| The SD card has been unplugged from the SD card slot, but the mount point has not been lifted |
Intent.action_media_bad_removal |
| Start scanning |
intent.action_media_scanner_started |
| Scan complete |
Intent.action_media_scanner_finished |
Android Mediascanner Usage Profile