Android(安卓)-- 文件扫描
16lz
2021-01-25
启动MediaScanner服务,扫描媒体文件,程序通过发送下面的Intent启动MediaScanner服务。
扫描指定文件
public void scanFile(Context ctx, String filePath) { Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); scanIntent.setData(Uri.fromFile(new File(filePath))); ctx.sendBroadcast(scanIntent); }
扫描指定目录
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); }
扫描Sallery
public void sdScan(){ sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); }
我是天王盖地虎的分割线
更多相关文章
- 一款常用的 Squid 日志分析工具
- GitHub 标星 8K+!一款开源替代 ls 的工具你值得拥有!
- RHEL 6 下 DHCP+TFTP+FTP+PXE+Kickstart 实现无人值守安装
- Linux 环境下实战 Rsync 备份工具及配置 rsync+inotify 实时同步
- Android调用ITelephony类的endCall()方法
- 【Android】通知的实现
- Android[中级教程]第二章 数据存储之File
- 在android style.xml文件中使用自定义属性
- Android文件存储(写入,读取,删除)