首页 > 移动平台 > 详细

Android -- 文件扫描

时间:2014-11-21 23:06:18      阅读:292      评论:0      收藏:0      [点我收藏+]

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

我是天王盖地虎的分割线                                                             

Android -- 文件扫描

原文:http://www.cnblogs.com/yydcdut/p/4114383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!