正文  数据库 > 文件存储/SD卡 >

Android: 获取显示SD卡文件列表

读取SD卡文件信息,添加到ListView中显示出来:ListView取得SD文件信息的代码:List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); String sDStateString = Environm......

读取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;

 

根据filetype画不同图片: