I need to change the file path to work with my web application from which I upload files to my android device to an external sd card...
This code was working on android 2.2 tablet long time ago, now I have to make a change to work on tablet with Android 4.4.2, but I don't know what should I change because I'm not very much a coder myself.
I installed "FX file explorer", I put some file on my external sd card, then when I press on "file>details" for a while I get
PATH System/storage/sdcard1/filename
FILESYSTEM PATH /storage/sdcard1/filename
REAL PATH storage/sdcard1/filename
Here is my code from my app... I use Android studio
public static File parseMountDirectory() {
File dir_00 = new File(URI.create("file:///storage"));
File dir_01 = new File(Environment.getExternalStorageDirectory() + "/ext_sdcard");
File dir_1 = new File(Environment.getExternalStorageDirectory() + "/sdcard1");
File dir_2 = new File(Environment.getExternalStorageDirectory() + "/sdcard2");
File dir_3 = Environment.getExternalStorageDirectory();
return dir_01.exists() ? dir_01 : dir_00.exists() ? dir_00 : dir_1.exists() ? dir_1 : dir_2.exists() ? dir_2 : dir_3.exists() ? dir_3 : null;
}
Starting in Kitkat , you need permission for read/write opperations on the external storage :
Make sure to add the permissions in your AndroidManifest
.xml like this :
<manifest .. >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.