DeveloperPaul123 / FilePickerLibrary

Simple library that allows for the picking of files and/or directories.
Apache License 2.0
79 stars 25 forks source link

Navigation to the external SD card #3

Open u2gilles opened 9 years ago

u2gilles commented 9 years ago

Is it possible to navigate to the external SD card. I can't select it. Thanks in advance and kind regards.

DeveloperPaul123 commented 9 years ago

Ill look into this. Does it work when you try the demo app?

u2gilles commented 9 years ago

Same with the demo. I looked into the code and the problem is that you are using Environment.getExternalStorageDirectory(), which return the top directory of the internal memory of the device, On my samsung S4, this is : /storage/emulated/0/. But the top directory of the SD card is /storage/extSdCard. Of course you can't hardcode these names as different manufacturers use different names. Good luck.

DeveloperPaul123 commented 9 years ago

It seems like I just need to make the parent directory just /storage, then the user can navigate wherever they want to. What I think I'm going to do is allow users to pass a start directory themselves and that way you can make it whatever you'd like.

u2gilles commented 9 years ago

I cloned locally your lib. When I tried this method, there were plenty of drives like usb1, usb2 etc... and when you click on it the app crashes. I read in forums that /storage/extSdCard not be the same on all decices. If you hardcode the sd drive, I recommend that you test the existence of "/storage/extSdCard" folder.

In my case, I had the top sd card directory availabe in my app so I just pass it to the cloned lib in the intend. The way I got it in my app (an ActionBarActivity) is not so nice but pretty safe I think. Basically I took 4 times the parent of the sd app root folder (/storage/extSdCard/Android/data/myapp/files) to get the sd drive root folder (/storage/extSdCard). But it is only a personal app (not for the store). I was lazy to look up in the official API.

isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

File[] files = android.support.v4.content.ContextCompat.getExternalFilesDirs(this, null); appFolderDevice = files[0].toString(); if (isSDPresent){ appFolderSD = files[1].toString(); File appFolderSDFile = new File(appFolderSD); appFolderSDFile = appFolderSDFile.getParentFile().getParentFile().getParentFile().getParentFile(); rootFolderSD = appFolderSDFile.getAbsolutePath(); }

DeveloperPaul123 commented 9 years ago

Did the code above work?

u2gilles commented 9 years ago

yes but i tested it only on my samsung s4. It should also work on all android devices as they all should have the same file system structure (application folder at the fourth level). I cross fingers.

DeveloperPaul123 commented 9 years ago

Ok Ill let you know what happens

Madaditya commented 8 years ago

First,thank you for your work. External Sd card doesnt work here at Marshmellow. Any Help?

DeveloperPaul123 commented 8 years ago

@Madaditya this is still a work in progress. I haven't had the opportunity to add this feature yet but it's on the list of todos.