显示SD卡里的文件列表
读取SD卡文件信息,添加到ListView中显示出来:
ListView取得SD文件信息的代码:
- List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
- String sDStateString = Environment.getExternalStorageState();
- if (sDStateString.equals(Environment.MEDIA_MOUNTED)) {
- try {
- File SDFile = Environment.getExternalStorageDirectory();
- File sdPath = new File(SDFile.getAbsolutePath());
- if (sdPath.listFiles().length > 0) {
- for (File file : sdPath.listFiles()) {
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("text_content", file.getName()); //get filename
- list.add(map);
- }
- }
- } catch (Exception e) {
- //
- }
- }
- return list;