一、MediaScanner 的使用
1)Intent.ACTION_MEDIA_SCANNER_SCAN_FILE:扫描指定文件
public void scanFileAsync(Context ctx, String filePath) {
Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
scanIntent.setData(Uri.fromFile(new File(filePath)));
ctx.sendBroadcast(scanIntent);
}
2)“android.intent.action.MEDIA_SCANNER_SCAN_DIR”:扫描指定目录
public static final String ACTION_MEDIA_SCANNER_SCAN_DIR = "android.intent.action.MEDIA_SCANNER_SCAN_DIR";
public void scanDirAsync(Context ctx, String dir) {
Intent scanIntent = new Intent(ACTION_MEDIA_SCANNER_SCAN_DIR);
scanIntent.setData(Uri.fromFile(new File(dir)));
ctx.sendBroadcast(scanIntent);
}
二、MediaScanner 框架
![](https://images2017.cnblogs.com/blog/195250/201712/195250-20171210224330958-475771846.png)
三:MediaScanner 流程
![](https://images2017.cnblogs.com/blog/195250/201712/195250-20171210224612130-640032865.png)