Where in Android file system are directories created? - android

I am working on Android app that has to save data to files. To make the files accessible for all apps and also transfer to computer through USB, the files should be saved in a folder called "ABC". I manually created the folder "ABC" on both external storage card and internal storage. I was able to get full path of that folder on external storage card through code and was able to write and read from it.
String path = Environment.getExternalStorageDirectory().toString() + "/ABC";
But the internal storage turns out to be more elusive because I could not get the full path of "ABC" folder on the internal storage. Is there a way to programmatically determine where folders are created on internal storage? Generally, under what partion are folders created on internal storage in Android?
Edit:
Internal storage - I mean non-removable storage
External Storage - I mean Removable storage

I manually created the folder "ABC" on both external storage card and internal storage.
You might have created this directory on external storage. Unless you are testing on a device or emulator, you did not create this directory on internal storage, as you do not have access to it. A "card" would imply removable storage, which is something else entirely, for the vast majority of Android devices.
I was able to get full path of that folder on external storage card through code and was able to write and read from it.
Your code is for external storage. On very few devices is that a "card".
But the internal storage turns out to be more elusive because I could not get the full path of "ABC" folder on the internal storage.
There is no "ABC" folder on internal storage, insofar as you cannot create a /ABC directory off of the device root, or even off of /data. You can only work for your app's portion of internal storage, using methods like getFilesDir(). And, again, unless you are testing on an emulator or a rooted device, you have no means of creating such an "ABC" directory by hand.
Is there a way to programmatically determine where folders are created on internal storage?
Um, well, you are certainly welcome to examine the path in the File object that you created to point to some location (e.g., new File(getFilesDir(), "ABC")).
Generally, under what partion are folders created on internal storage in Android?
/data.

Related

How to get absolute path of Internal Storage in Android

Internal Storage Path
Consider the above picture. It shows the folders and file in internal storage. My problem is i am not able to get the absolute path of the internal storage. I Have tried using
String path = getFilesDir().getAbsolutePath();
but it is giving me the path of my app storage. My objective is to backup a file from the private storage of my app to the top of internal storage. And i am unable to find a solution on web and neither on stack overflow. Suggest a solution to this problem!
Environment.getExternalStorageDirectory();
Return the primary shared/external storage directory.
Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.
File dir = Environment.getExternalStorageDirectory();
String path = dir.getAbsolutePath();
It is only possible with root access. You should write you backup to external storage to make it world-readable. Android docs says that if you want to share file with other apps or store this file even after app will be deleted you should save it to external storage. Android docs
Try this,
String path = Environment.getExternalStorageDirectory().getAbsolutePath();

Where are files saved in PhoneGap app stored on Android?

I am using PhoneGap with File plugin. I am able to read & write files to file system and those are persisted correctly. But when I try to locate those files from native file explorer app on tablet or from Windows Explorer (through USB connection), I can't find any traces of these files by browsing to folder that PhoneGap claims to store those (Tablet\Android\data\com.xxx.yyy\files) to nor with search functionality. I do not have any external cards attached to my Android tablet. Any ideas how to find those files?
After carefully studying Android documentation about storage options I spotted that this is the intended behavior of internal storage which is used for applications private data that shouldn't be possible to read by other applications accessing the file system.
I have all the time thought that the external referred to SD cards but instead the external storage is described like this
Every Android-compatible device supports a shared "external storage"
that you can use to save files. This can be a removable storage media
(such as an SD card) or an internal (non-removable) storage. Files
saved to the external storage are world-readable and can be modified
by the user when they enable USB mass storage to transfer files on a
computer.
which seems to be the exact behavior I was looking for. By using the cordova.file.externalDataDirectory, I was able to store the files on internal file system (not to SD card) and see them in the file explorer.
I think that the assumption of external storage referring to SD card only isn't totally unreasonable since the File plugin has / as a directory for cordova.file.externalRootDirectory in file system layout for Android. This must have been the thing that made me think that way.

Preference of storage in android

I have created one app which creates one file on external memory, but when I install it on different devices the files are created in internal sdcard in some device and not created in external(Physical) sd card.
My question is that. How do we decide between the internal or external sdcard.
Which has more preference to store file by default in android?
I use the
Environment.getExternalStorageDirectory()+ "PolicyTaskfile"+"/filename.txt";
It gives external or internal sdcard path depending on the device.
The short answer is that you do not get to pick. It's up to the OEM to decide whether external storage is truly SD card or just an internal storage device (for example: eMMC). With KitKat there is a notion of primary and secondary external storage, but no easy API to determine which you are using or which is really removable media.

Get external storage parent folder on android

I've an application on the Play Store, and a user sent me a bug report saying that on his device the external sdcard is not listed in the external storage device list, though is mounted and accessible at /mnt/external_sd
I have a dialog listing folders and start directory is Environment.getExternalStorageDirectory().
After some clicks to get to the parent folder, the /storage folder is reached and getParent() returns null.
Which starting folder should I set to have access to the full storage structure?
EDIT:
As a workaround I am adding in my app preference the ability to choose if the storage root directory should be Environment.getExternalStorageDirectory() or hardcoded /mnt.
Comment/answer if there are best alternatives.
Get external storage parent folder on android
By external storage, I am assuming that you meant micro SD card storage.
external sdcard is not listed in the external storage device list,
though is mounted and accessible at /mnt/external_sd
You cannot access SD storage by using Environment.getExternalStorageDirectory() method.
Before API level 19, there was no official way to store in SD card. But, many could do it using unofficial APIs.
Officially, one method was introduced in Context class in API level 19 (Android version 4.4 - Kitkat).
File[] getExternalFilesDirs (String type)
It returns absolute paths to application-specific directories on all
shared/external storage devices where the application can place
persistent files it owns. These files are internal to the application,
and not typically visible to the user as media.
That means, it will return paths to both Micro SD card and Internal memory. Generally, second returned path would be storage path of micro SD card.
The Internal and External Storage terminology according to Google/official Android docs is quite different from what we think.

Way to save application cache in internal sdcard in android?

In my application , downloading lot of files from server. I want to cache them in sdcard.
for that am using fallowing api..
context.getExternalCacheDir();
But problem is that, not able to save them in internal sdcard(i.e; non removable external storage).They are saving in to "/mnt/sdcard/external_sd/Android/data/".
Please gimme a way to save may files in to non removable android cache.
Regards,
Srinivas
From intellisense for Environment.getExternalStorageDirectory:
"Gets the Android external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. You can determine its current state with getExternalStorageState().
Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.
In devices with multiple "external" storage directories (such as both secure app storage and mountable shared storage), this directory represents the "primary" external storage that the user will interact with.
Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace. Any files that are private to the application should be placed in a directory returned by Context.getExternalFilesDir, which the system will take care of deleting if the application is uninstalled. Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory(String)."

Categories

Resources