Android搜索sd卡文件
发布时间:2017-05-19 14:23:43 所属栏目:安卓资讯 来源:www.jianshu.com
导读:首先判断是否有sd卡booleansdCardExist=Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);if(sdCardExist){sdDir=Environment.getExternalStorageDirectory();searchFile(sdDir.getPath());//搜...
|
首先判断是否有sd卡booleansdCardExist=Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);if(sdCardExist){sdDir=Environment.getExternalStorageDirectory();searchFile(sdDir.getPath());//搜... 首先判断是否有sd卡boolean sdCardExist = Environment.getExternalStorageState() .equals(Environment.MEDIA_MOUNTED); if (sdCardExist) { sdDir = Environment.getExternalStorageDirectory(); searchFile(sdDir.getPath());//搜索調用方法 } else { Toast.makeText(mActivity, "没有sd卡", Toast.LENGTH_SHORT).show(); }搜索调用方法private void searchFile(String filePath) { File file = new File(filePath); List<File> folderList = new ArrayList<File>(); if (file.isDirectory()) { if (file.listFiles() != null) { for (File childFile : file.listFiles()) { if (childFile.isDirectory()) { folderList.add(childFile); } else { checkChild(childFile);//筛选结果返回 } } } } else { checkChild(file); } for (File folder : folderList) { searchFile(folder.getPath()); } }筛选结果返回方法 ,我是剔除图片文件private void checkChild(File childFile) { if (!childFile.getName().contains(".jpg") || !childFile.getName().contains(".png")) { if (childFile.length() / 1024 > 1024 * 10) { //创建模型类存储值,并添加到集合中。通过集合可做任意操作 PhotoInfo photoInfo = new PhotoInfo(childFile.getPath(), childFile.getName(), 0, false); list.add(photoInfo); } } } (编辑:无忧刷机网 - 51刷机网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
