Recently, I needed to write some data strictly on an external, removable media (aka SDCard). For lower devices without an βexternalβ internal storage (you know what I mean) this is not a problem since
Environment.getExternalStorageDirectory().getAbsolutePath() ,
which returns
/mnt/sdcard
- also the path to sdcard. However, on more expensive phones with built-in flash memory (e.g. sgs 2) /mnt/sdcard , which is returned from Environment.getExternalStorageDirectory().getAbsolutePath() is just an internal storage method. Real way to sdcard: `
/ highway / sdcard / external_sd`.
This does not stop here, however, as when I tried with sgs2, which was updated to ICS, the path to the SD card is now
/mnt/emmc .
Now I'm trying to create a general Utility class called ExternalStorage, which has a static method that returns the path to the sdcard root (as well as some other methods to get the total space, free space, space consumed by a specific dir, etc.) so far I have it:
Updated Version:
public static String getRemovableStoragePath() { File f = null; // Log.d(TAG, "Build.DEVICE: " + Build.DEVICE); // Log.d(TAG, "Build.MANUFACTURER: " + Build.MANUFACTURER); // Log.d(TAG, "Build.MODEL: " + Build.MODEL); if (Build.VERSION.RELEASE.startsWith("4")) { f = new File("/mnt/emmc"); } if (Build.MODEL.toLowerCase().startsWith("mele")) { return "/mnt/extern_sd0"; } if (Build.DEVICE.equals("nuclear-zoop") || Build.DEVICE.equals("nuclear-f900")) { f = new File("/mnt/extsd"); } String path = Environment.getExternalStorageDirectory().getAbsolutePath(); String extendedPath = ""; if (Build.DEVICE.toLowerCase().contains("samsung") || Build.MANUFACTURER.toLowerCase().contains("samsung")) { extendedPath = "/external_sd/"; try { f = new File(path + extendedPath); if (f.exists() && f.isDirectory()) { return f.getAbsolutePath(); } else if (Build.MODEL.toLowerCase().contains("gt-i9300")) { extendedPath = "/mnt/extSdCard/"; try { f = new File(extendedPath); if (f.exists() && f.isDirectory()) { return f.getAbsolutePath(); } } catch (Exception e) { // continue execution } } else { extendedPath = "/sd"; } } catch (Exception e) { // contine execution } } else if (Build.DEVICE.toLowerCase().contains("e0") || Build.MANUFACTURER.toLowerCase().contains("LGE")) { extendedPath = "/_ExternalSD/"; } else if (Build.MANUFACTURER.toLowerCase().contains("motorola") || Build.DEVICE.toLowerCase().contains("olympus")) { f = new File("/mnt/sdcard-ext"); } try { if (!extendedPath.equals("")) { f = new File(path + extendedPath); } if (f.exists() && f.isDirectory()) { // Log.d(TAG, "path: " + f.getAbsolutePath()); return f.getAbsolutePath(); } else { } } catch (Exception e) { // e.printStackTrace(); // f is probably null. no need to print stacktrace. return path; } return path; // return Environment.getExternalStorageDirectory().getAbsolutePath(); }
Has anyone done this already? I know that I am missing many mfg-specific paths, so I need help completing this utility to support as many Android phones as possible.
josephus
source share