Reputation: 3940
After reading Android documentation and Stackoverflow discussion about all storage types, and after viewing filesystems on a number of android devices, I'm a bit cofused.
Given the following results-
getFilesDir()
- returns /data/data..
getExternalFilesDir()
- returns /mnt/sdcard/Android/data/<ap_name>/files
getExternalStorageDirectory()
- returns /mnt/sdcard/
And given the fact that the file system Windows shows me when I'm connecting my device using USB:
device\Card - contains DCIM, Images (folders) ...
device\Phone - contains WhatsApp, PicArts, Pou (apps folders) ...
And given the fact that when openning My Files
app, the path is /sdcard/
and it contains all the apps folder (WhatsApp, PicsArts..),
There are things I do not understand, such as:
How come the Device/Phone
contain what /mnt/sdcard/
contains? why isn't it contained in Device/Card
?
are those results mean that all those known apps use the external storage as the default storage type for media files?
My intention is to create and maintain a directory in the android file system and to store media files in there.
I want this folder to be placed where all the other apps place their folder , in this case is /sdcard/
as shown in My Files
app (or /mnt/sdcard
as the full path), but I dont want it to be depend on whether or not the device have an availble external storage.
What should I do?
Upvotes: 0
Views: 614
Reputation: 28726
Few remarks regarding storage :
getExternalFilesDir()
will be the same on all devicesgetFilesDir()
will be the same on all devicesgetExternalStorageDirectory()
will be the same on all devicesSo don't rely on hardcoded absolute path in your code if you need that your app run on different devices.
Every Android device have 2 storage space (mainly for historical reason) : the internal and the external.
Major differences between them :
internal storage :
getFilesDir()
external storage :
getExternalFilesDir()
(to get a directory dedicated to your app) or getExternalStorageDirectory()
to get the root of the external storage.Remark about external storage : today, many vendors use a virtual external storage. i.e. there is no removable sd-card; but instead there is a partition of the internal memory that is mounted as if it was an external storage (so even on those devices the external storage is not available just after a reboot).
I want this folder to be placed where all the other apps place their folder
There is no such place. All the other apps are free to put their data either on the internal storage or on the external storage.
How come the Device/Phone contain what /mnt/sdcard/ contains? why isn't it contained in Device/Card?
Only external storage is visible when your device is USB-connected. The path Device/Phone is choose by the the usb driver (and so not really relevant). The important thing is that under this path you only see the content of root external storage (i.e. the content of the directory returned by getExternalStorageDirectory()
)
Upvotes: 2
Reputation: 3033
In my Apps I always use:
fileMedia = Environment.getExternalStorageDirectory().getAbsolutePath() + "/yourappdirectoryonsdcard/" + "MediaFileName.3gpp";
File outFile = new File(fileMedia);
if (outFile.exists()) {
outFile.delete();
}
and don't have problems with available external storage detecting.
Upvotes: 1