Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between getExternalStorageDirectory and getExternalStoragePublicDirectory?

According to google one returns the primary shared/external storage directory and the other gets a top-level shared/external storage directory for placing files of a particular type. Can anyone explain in simple language and example?

like image 479
indian0 girl Avatar asked May 25 '17 10:05

indian0 girl


People also ask

What can I use instead of getExternalStoragePublicDirectory?

For api 28 and below, you need getExternalStoragePublicDirectory() method but it is deprecated. What if you don't want to use that deprecated method? Then you can use SAF file explorer(Intent#ACTION_OPEN_DOCUMENT). As said in the question, this requires the user to pick the location manually.

What is getExternalStorageDirectory?

getExternalStorageDirectory() Path to a directory where the application may access top level storage. The current operating system should be determined before issuing this function call, as this functionality is only available on Android.

What is getExternalFilesDir?

getExternalFilesDir() It returns the path to files folder inside Android/data/data/your_package/ on your SD card. It is used to store any required files for your app (e.g. images downloaded from web or cache files). Once the app is uninstalled, any data stored in this folder is gone too. getExternalStorageDirectory()


1 Answers

I am going to assume that you have used a Windows computer sometime in your life.

Environment.getExternalStorageDirectory(), if this were Windows, would return C:\.

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), if this were Windows, would return some standard location on the C:\ drive where the user would typically look to find saved movies.

like image 181
CommonsWare Avatar answered Sep 18 '22 11:09

CommonsWare