I would like to get in my file browser File reference to external disk not SD Card. I mean I know that there is method
Environment.getExternalStorageDirectory();
But to my knowledge this will get reference to SD Card. But how to get external disk (say kind of USB storage attached to Android device)? You know that device can have both SD card and external USB stick attached to them.
But how to get external disk (say kind of USB storage attached to Android device)?
Android does not support this. If particular devices do, you would have to ask their manufacturers what they recommend.
In the end I have selected following solution:
1) Enlisting all existing roots using:
File[] roots=File.listRoots();
2) check presense among those roots standard ones, i.e.
File phoneRoot=new File("//");
File sdRoot=Environment.getExternalStorageDirectory();
3) If there are some extra ones - treat them as those additional external disks/sticks
I think it's best solution, since no hacks, everything is standard and this covers possible future extensions.
Related
mySound.load(new URLRequest("file://mnt/sdcard/AnyFolder/YourSound.mp3"));`<br/>
I want to detect the name of the sdcard at runtime, so i can store my app-data on external storage.
The above codeline is an example of storing a mp3 to user's required location.
Maybe you are asking for:
File f = new File(Environment.getExternalStorageDirectory() +
"/" + "yourfilename");
I also recomend you to avoid writing to the root of the SD card. It is a good practice to write your aplication data into the appropriate folder:
File f = new File(Environment.getExternalStorageDirectory() +
"/Android/data/com.example.testapp/" + "yourfilename");
Obviously, you have to change the "com.example.testapp" with your app package (the package you entered when you created the project in Eclipse/Android Studio).
getExternalStorageDirectory()
in
http://developer.android.com/reference/android/os/Environment.html
use Environment.getExternalStorageState() it will give path to internal SD mount point like "/mnt/sdcard"
First, on Android 4.4+, you do not have write access to removable media (e.g., "external SD"), except for any locations on that media that might be returned by
getExternalFilesDirs() and getExternalCacheDirs().
See Dave Smith's excellent analysis of this, particularly if you want the low-level details.
Second, lest anyone quibble on whether or not removable media access is otherwise part of the Android SDK, here is Dianne Hackborn's assessment:
...keep in mind: until Android 4.4, the official Android platform has not supported SD cards at all except for two special cases: the old school storage layout where external storage is an SD card (which is still supported by the platform today), and a small feature added to Android 3.0 where it would scan additional SD cards and add them to the media provider and give apps read-only access to their files (which is also still supported in the platform today).
Android 4.4 is the first release of the platform that has actually
allowed applications to use SD cards for storage. Any access to them
prior to that was through private, unsupported APIs. We now have a
quite rich API in the platform that allows applications to make use of
SD cards in a supported way, in better ways than they have been able
to before: they can make free use of their app-specific storage area
without requiring any permissions in the app, and can access any other
files on the SD card as long as they go through the file picker, again
without needing any special permissions.
I'm facing problem to detect all memory path in Android device.
If we try with provide tips and example we aren't able to getting proper external memory path.
For Example :
If we try to get external memory in Samsung Tab 2
Used code ::
Environment.getExternalStorageDirectory().getAbsolutePath()
It will provide us internal Mounted Memory path.
//storage/sdcard0/
After lot of googling i found one application which show all path of device
Application Name "ES Explorer"
This application showing all path of Memory.
Please provide us any solution so we can fix our problem
Beyond those types of storage volumes specifically supported by the standard Android SDK is a wide variety of vendor- and version- unique possibilities.
You can find all mounted filesystems by reading /proc/mounts as a text file.
However:
This will only find filesystems which are actually mounted - for example, it will not find USB storage volumes if they are handled as arbitrary USB accessories by an application, rather than mounted by the Linux operating system underlying Android.
You will have to apply some logic to filter out all the other various file systems which are not general storage devices and show up in the list. It used to be that you could detect "external" storage volumes by looking for "vfat" as a type, but that is no longer used in recent Android versions
Especially in recent Android versions, the actual path of the mount as discovered from /proc/mounts and the path customarily used may not match, as the customary path may redirect to the actual one by multiple levels of symbolic links
Samsung handles their storage a little differently than some other devices unfortunately. Ever since their version of Android 3.2, they have also disallowed the writing to the external storage by regular apps. That being said, you can still read(access) the external storages. Below are the paths to the two possible external storage locations. I actually have programmed specifically for the Galaxy Tab 2.0 (7 inch), so here ya go:
Inserted microSD card: mnt/extSdCard
Connected external storage via Samsung USB Adapter: mnt/UsbDriveA
"sdcard" storage(not an inserted SD card): getExternalStorageDirectory() as you know.
I've tried multiple ways to use functions to find the path, but haven't had any luck ever. However, this works, so I'm content. I hope it can help you too.
Please try to use bellow code.
public static File FileCache(Context context) {
// Find the dir to save cached images
File cacheDir;
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED))
cacheDir = new File(
android.os.Environment.getExternalStorageDirectory(),
"TechTool_Pdf");
else
cacheDir = context.getCacheDir();
if (!cacheDir.exists())
cacheDir.mkdirs();
return cacheDir;
}
I used to use the path="/sdcard/myapp" to save data.
However,the compiler suggests me to use Environment.getExternalStorageDirectory() instead of hardcode "/sdcard"
My Question is:
If I do this, would the users of myapp lost their data when they updates?
AND, if true , how to prevent?
Sometimes, certain device manufacturers might use a different path for the external storage. Some devices might not have external storage at all and consider a part of their onboard storage as external storage. At other times, "/sdcard" might be mapped to another storage area as well.
So it is generally not considered wise to use "/sdcard".
On the other hand, Environment.getExternalStorageDirectory() is a system API and will always be supported by all device manufacturers. It will always correctly map to the storage area which is meant to be used as external storage for that particular device. So you can use this safely whenever you need a reference to the external storage directory.
Not all devices have sdcard. Some have build in storage like tablets. Therefore you should using the external storage directory.
Could be that it is directory mapped to /sdcard but could be some other directory/mount.
To answer your question: no, they will not loose there data.
I just want to view the files(especially the .png files) associated with one of the application in my mobile. The application is actually installed(moved) in the SD card.
The issue is ..I could not find the application in the SD card. I am using a file browser called 'File Manager' to browse through the SD card. Can someone help me on this.
It should be here:
/mnt/sdcard/Android/data/your_package_name/
Some hardware implements the path to the external storage different.
/mnt/sdcard/Android/data/your_package_name/
/mnt/sdcard-ext/Android/data/your_package_name/
You may be able to get a better view of what is on the device by using the ADB Shell. If you still have trouble at this point trying running grep or find from the shell.
UPDATE
Most of the time the files associates with your application are in the directory with your application. The application is installed in /data/data/your.package.name/. However you will need root access to get here if you are on a phone, I think the emulator lets you get here. As far as external storage... yea its a pain, to much fragmentation in the market. You have to programmatically check the location of the external storage.
On my device with Android 2.3.6 apps moved on the SD card are located into a directory named .android_secure as .asec files (see http://www.fileinfo.com/extension/asec).
They are not visible from the standard "Archive" browser which shows the hidden directory as empty.
The files are also encrypted so I guess no access to the images within is possible.
I found that using Environment object isn't reliable;e to determinate SD card. Actually it works, however sometimes tells like as no SD card, so I use just direct mount as /sdcard and it works. Now I realized that a device may have several SD cards. My device report it as external-sdcard, so I can access this card as /external-sdcard or /sdcard/external-sdcard. Now question, how to figure out type of a particular mount? I can traverse directory, but File object doesn't have any attribute telling me I am SD card. I remember regular Java provides FileSystem objects which I can use to inspect particular files and this object can tell me if a File object is simple file, or it is drive, or it is external drive. Is something like that available for Android?
AFAIK, the currently documented API only supports one SD card (actually external storage).
You can use Environment.getExternalStorageDirectory() to get the directory, and Enviroment.getExternalStorageState() to check if it is mounted.
Anything besides that seems to be (currently) unsupported.
Bearing that in mind, you could parse /proc/mounts to find out what file systems are mounted where.