47

I am trying to save a file to my SDcard on my Samsung Galaxy Nexus running 4.2.2. From my app I am using

Environment.getExternalStorageDirectory()

But it returns

/storage/emulated/0/

Which is not where my SDcard information is located to. Is there any working method I can use to get the correct path to my SDcard?

Luke Pring
  • 992
  • 3
  • 11
  • 16

7 Answers7

15

Actually, that is the correct location.

From android 4,2 onwards, Google introduced multiple user accounts. Every user has his/her own external storage, which has the user ID in the path to maintain uniqueness.

The primary (default) user's ID is 0. So you get /storage/emulated/0/ as the path to the external storage.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
10

I just learned this is the Jelly Bean's way of dealing with the lack of android.permission.WRITE_EXTERNAL_STORAGE permission. I haven't seen such a behavior with older versions of Android.

Just add this line to your AndroidManifest.xml:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
ohaleck
  • 661
  • 4
  • 20
  • 26
    This doesn't fix it per se. I have that set in my Manifest and it still comes back as **/storage/emulated/0**. When I use the shell for the device **/storage/emulated/0** doesn't exist. Instead of **0**, **legacy** is there. – Michael Nguyen Aug 14 '14 at 05:48
  • 4
    @MichaelNguyen You can not see the **/storage/emulated/0** directory from adb shell (not even as root). It only exists in the processes launched by the user. You should see it from a terminal emulator on the device, and access it from any app. – ge0rg Mar 18 '15 at 17:06
5

Environment.getExternalStorageDirectory() refers to whatever the device manufacturer considered to be "external storage". I can be something else than the SD-card.

You may get more informations here: Find an external SD card location

Community
  • 1
  • 1
Alban Dericbourg
  • 1,616
  • 2
  • 16
  • 39
1

I think its because of using genymotion emulator, the path is true and in Eclipse it locates at

File Explorer - > mnt - > shell - > emulated -> 0 

hope it helps ;)

David
  • 15,894
  • 22
  • 55
  • 66
farshad22
  • 31
  • 1
  • 8
0

Sure? Where do you think your sdcard is mounted? Try doing ls -l on that directory – it's probably a symlink to /storage/emulated/0/.

thejh
  • 44,854
  • 16
  • 96
  • 107
  • I'm using ls -l at the moment for a different app, the symlink shows up to the app but not to my terminal which is the weirdest thing. – Luke Pring Jun 04 '13 at 11:02
0

I had somehow lost my symlink at /storage/emulated/0, causing a similar failure. What I did was use the camera app to take a picture. I observed that the pictures details said it was within /storage/emulated/0, though that directory did not exist from the file explorer. Then I rebooted the phone. After reboot the link existed.

Frank Schwieterman
  • 24,142
  • 15
  • 92
  • 130
-1

Try to use getExternalFilesDir() or getExternalStoragePublicDirectory().

From Android 4.2 documentation

Damien R.
  • 3,383
  • 1
  • 21
  • 32
  • Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) returns a path of /storage/emulated/0/Pictures Which still is invalid on my N7 – VMcPherron Apr 09 '14 at 16:10
  • And I understand that it should be available for the application (not adb) during runtime, but cannot find any files in that directory when I clearly have multiple files. (ls /mnt/shell/emulated/0/Pictures/*jpg) – VMcPherron Apr 09 '14 at 16:22