diff options
Diffstat (limited to 'main/src/cgeo/geocaching/files/LocalStorage.java')
| -rw-r--r-- | main/src/cgeo/geocaching/files/LocalStorage.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java index ec09433..d10f12b 100644 --- a/main/src/cgeo/geocaching/files/LocalStorage.java +++ b/main/src/cgeo/geocaching/files/LocalStorage.java @@ -14,6 +14,7 @@ import android.os.Environment; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; +import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -24,6 +25,8 @@ import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; /** * Handle local storage issues on phone and SD card. @@ -389,4 +392,47 @@ public class LocalStorage { }; return LocalStorage.getStorageDir(geocode).listFiles(filter); } + + /** + * Get all storages available on the device. + * Will include paths like /mnt/sdcard /mnt/usbdisk /mnt/ext_card /mnt/sdcard/ext_card + */ + public static List<File> getStorages() { + + String extStorage = Environment.getExternalStorageDirectory().getAbsolutePath(); + List<File> storages = new ArrayList<File>(); + storages.add(new File(extStorage)); + File file = new File("/system/etc/vold.fstab"); + if (file.canRead()) { + FileReader fr = null; + BufferedReader br = null; + try { + fr = new FileReader(file); + br = new BufferedReader(fr); + String s = br.readLine(); + while (s != null) { + if (s.startsWith("dev_mount")) { + String[] tokens = StringUtils.split(s); + if (tokens.length >= 3) { + String path = tokens[2]; // mountpoint + if (!extStorage.equals(path)) { + File directory = new File(path); + if (directory.exists() && directory.isDirectory()) { + storages.add(directory); + } + } + } + } + s = br.readLine(); + } + } catch (IOException e) { + Log.e("Could not get additional mount points for user content. " + + "Proceeding with external storage only (" + extStorage + ")"); + } finally { + IOUtils.closeQuietly(fr); + IOUtils.closeQuietly(br); + } + } + return storages; + } } |
