Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm saving a picture like so:

File dcimDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File picsDir = new File(dcimDir, "MyPics");
picsDir.mkdirs(); //make if not exist
File newFile = new File(picsDir, "image.png"));
OutputStream os;
try {
    os = new FileOutputStream(newFile);
    target.compress(CompressFormat.PNG, 100, os);
    os.flush();
    os.close();
    b.recycle();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();

However, when I look for the image through windows it is in the internal memory, the gallery confirms this:

This last one is confusing, it says internal memory, but then also has sdcard0 in file path.

So when does external not mean external? Is it a device set up thing, or an I miss-using/miss-understanding getExternalStoragePublicDirectory?

The MTP engine sometimes reports getExternalStorageDirectory() as "Internal Storage", which is why it shows up under that name when you mount the device as a volume on Windows, Linux, etc.

External storage has always meant the storage that the user can access by means of a USB cable. The "Internal Storage" label is probably used on devices where external storage is part of the on-board ("internal") flash.

And how should I be getting a path to the SD card if getExternalStorageDirectory is behaving this way? – weston Oct 19, 2013 at 13:13 Thanks, but I am using Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) and it isn't placing on the physical SD card. – weston Oct 19, 2013 at 13:29 @weston: It is not supposed to place it on the physical SD card, according to the manufacturer of your device. Quoting the documentation that I linked to in my previous comment: "It's possible that a device using a partition of the internal storage for the external storage may also offer an SD card slot. In this case, the SD card is not part of the external storage and your app cannot access it (the extra storage is intended only for user-provided media that the system scans)". – CommonsWare Oct 19, 2013 at 13:40 Ok, I do now understand why it works this way. Doesn't help me place files on the sd card. My users do not understand how their built in camera apps can use the sd card and my app can't. So, you are saying that writing to sd card is impossible if the device has internal storage? – weston Oct 19, 2013 at 20:38 @pillesoft: "I mean how to ensure that you really save files to the physical SD Card?" -- you do not have filesystem access to removable storage on Android 4.4+, outside of a couple of app-specific locations. "Do you have any android provided solution for this?" -- what you want is not strictly possible prior to perhaps Android 7.0, where you can get access to a StorageVolume (with user approval). For Android 5.0-6.0, you can use ACTION_OPEN_DOCUMENT_TREE to have the user give you access to a document tree, but it might not be the magic one you are seeking. – CommonsWare Jul 7, 2017 at 11:09

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.