Java tutorial
//package com.java2s; /***************************************************************************** * Util.java ***************************************************************************** * Copyright 2011-2014 VLC authors and VideoLAN * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.StringTokenizer; import android.os.Environment; public class Main { public static String[] getStorageDirectories() { String[] dirs = null; BufferedReader bufReader = null; ArrayList<String> list = new ArrayList<String>(); list.add(Environment.getExternalStorageDirectory().getPath()); List<String> typeWL = Arrays.asList("vfat", "exfat", "sdcardfs", "fuse"); List<String> typeBL = Arrays.asList("tmpfs"); String[] mountWL = { "/mnt", "/Removable" }; String[] mountBL = { "/mnt/secure", "/mnt/shell", "/mnt/asec", "/mnt/obb", "/mnt/media_rw/extSdCard", "/mnt/media_rw/sdcard", "/storage/emulated" }; String[] deviceWL = { "/dev/block/vold", "/dev/fuse", "/mnt/media_rw/extSdCard" }; try { bufReader = new BufferedReader(new FileReader("/proc/mounts")); String line; while ((line = bufReader.readLine()) != null) { StringTokenizer tokens = new StringTokenizer(line, " "); String device = tokens.nextToken(); String mountpoint = tokens.nextToken(); String type = tokens.nextToken(); // skip if already in list or if type/mountpoint is blacklisted if (list.contains(mountpoint) || typeBL.contains(type) || StartsWith(mountBL, mountpoint)) continue; // check that device is in whitelist, and either type or mountpoint is in a whitelist if (StartsWith(deviceWL, device) && (typeWL.contains(type) || StartsWith(mountWL, mountpoint))) list.add(mountpoint); } dirs = new String[list.size()]; for (int i = 0; i < list.size(); i++) { dirs[i] = list.get(i); } } catch (FileNotFoundException e) { } catch (IOException e) { } finally { if (bufReader != null) { try { bufReader.close(); } catch (IOException e) { } } } return dirs; } private static boolean StartsWith(String[] array, String text) { for (String item : array) if (text.startsWith(item)) return true; return false; } }