Click here to Skip to main content
15,902,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to get path of external SD attached to mobile.

path like :
mnt/SDCARD0

mnt/extsdcard.

problem is that it differs from mobile to mobile.
Posted
Updated 23-Oct-16 19:12pm

That is a true headache. So hard-code path is out of question. There are some solutions on the web to get the path programmatically, but no gaurantee:
1. android-finding-sd-card-path[^]
2. get-external-sdcard-location-in-android[^]
 
Share this answer
 
Comments
garav kumar mishra 27-Jan-14 7:10am    
it does not seem to works ??
The below code will helps...
Java
/**
     * Returns all available external SD-Card roots in the system.
     *
     * @return paths to all available external SD-Card roots in the system.
     */
    public static String[] getStorageDirectories() {
        String[] storageDirectories;
        String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE");

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            List<string> results = new ArrayList<string>();
            File[] externalDirs = myContext.getExternalFilesDirs(null);
            for (File file : externalDirs) {
                String path = null;
                try {
                    path = file.getPath().split("/Android")[0];
                } catch (Exception e) {
                    e.printStackTrace();
                    path = null;
                }
                if (path != null) {
                    if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Environment.isExternalStorageRemovable(file))
                            || rawSecondaryStoragesStr != null && rawSecondaryStoragesStr.contains(path)) {
                        results.add(path);
                    }
                }
            }
            storageDirectories = results.toArray(new String[0]);
        } else {
            final Set<string> rv = new HashSet<string>();

            if (!TextUtils.isEmpty(rawSecondaryStoragesStr)) {
                final String[] rawSecondaryStorages = rawSecondaryStoragesStr.split(File.pathSeparator);
                Collections.addAll(rv, rawSecondaryStorages);
            }
            storageDirectories = rv.toArray(new String[rv.size()]);
        }
        return storageDirectories;
    }


</string></string></string></string>
 
Share this answer
 
Comments
Dave Kreskowiak 24-Oct-16 1:29am    
I doubt the OP is still looking for an answer almost THREE YEARS later.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900