Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

Is there a way I can use ADB to determine the external storage directory (equivalent of the Android API call Environment.getExternalStorageDirectory())?

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

adb shell echo $EXTERNAL_STORAGE. All credit goes to Flow for leading me to experiment and find this.

Naturally you can use cd $EXTERNAL_STORAGE or whatever else you might need during an adb shell session.

share|improve this answer
2  
Good Teamwork :) +1 –  Flow Oct 3 '11 at 20:19
1  
Very good! Thanks! Note, though, that if you may need to escape $ depending on your shell. example: adb shell echo \$EXTERNAL_STORAGE –  stephelton Oct 3 '11 at 20:43
    
Hmm, it turns out that my samsung vibrant gives me a different value for $EXTERNAL_STORAGE than it does Environment.getExternalStorageDirectory(). This isn't the first nasty bug I've found on this phone. –  stephelton Oct 3 '11 at 22:16
    
@stephelton That's disappointing. Which one's incorrect? $EXTERNAL_STORAGE is correct for me, /mnt/sdcard/external_sd/. –  Matthew Read Oct 12 '11 at 21:15
add comment

I don't think that this is possible. See Matthew's Post

But let's have a lock on how Environment.getExternalStorageDirectory() returns the external storage directory. A quick look in android/os/Environment.java shows that all this method does, is returning a static constant File member called EXTERNAL_STORAGE_DIRECTORY. This constant is initialized by

private static final File EXTERNAL_STORAGE_DIRECTORY
        = getDirectory("EXTERNAL_STORAGE", "/sdcard");

which calls getDirectory()

static File getDirectory(String variableName, String defaultPath) {
    String path = System.getenv(variableName);
    return path == null ? new File(defaultPath) : new File(path);
}

So the external storage directory is nothing else then an java System environment variable (or a predefined default). You could try to follow this trace further. Maybe the external storage directory is just a hard coded path in some configuration file on the filesystem. Or maybe there is a way to read out these environment variables via adb that I don't know.

share|improve this answer
2  
I figured out the adb command using this info, +1. –  Matthew Read Oct 3 '11 at 20:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.