Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment.getExternalStoragePublicDirectory gives internal storage

Tags:

android

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:

On PC

Gallery details

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?

like image 239
weston Avatar asked Oct 19 '13 12:10

weston


People also ask

What is environment getExternalStorageDirectory?

getExternalStorageDirectory() Return the primary shared/external storage directory. static File. getExternalStoragePublicDirectory(String type) Get a top-level shared/external storage directory for placing files of a particular type.

What is external storage directory?

Android External Storage: a place to store addition data of Android, the files that you store here is not applied the security system. Usually there are two types of external storage: Fixed external storage: Commonly understood as the hard drive of the device. Removable storage: Such as SD Card.

What is external storage path in Android?

Android External Storage Example Code getExternalFilesDir(): It returns the path to files folder inside Android/data/data/application_package/ on the SD card. It is used to store any required files for your app (like images downloaded from web or cache files).


1 Answers

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.

like image 199
CommonsWare Avatar answered Oct 07 '22 04:10

CommonsWare