Android -- 文件扫描

启动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())));     
    }

我是天王盖地虎的分割线                                                             

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。