0

I want to allow the user to choose a file in the explorer. (Specifically a PDF file only)

I searched a little, but I don't arrive to find something in the developer doc Android.

There is nothing to do it easily ?

For example, I want something like GMAIL uses when the user wants to join a file to a mail.

Thx for help,

deveLost
  • 1,151
  • 2
  • 20
  • 47

1 Answers1

1

Sadfully, you have to write an fileexplorer yourself or us an external fileexplorer (which isn't always present). As I've got the same problem the last days, this might help you: https://stackoverflow.com/a/25724970/3960095. It's a filebrowser in a Fragment. Feel free to use it :)

Community
  • 1
  • 1
Kevin Gebhardt
  • 368
  • 1
  • 12
  • don't forget to change FILE_SUFFIX(at the beginning of class FileAdapter) to ".pdf" for only showing pdf-files. You'll also need two pictures ic_folder and ic_file in your drawable-XXX-Folder, which should be the picture for a Folder and a File... – Kevin Gebhardt Sep 11 '14 at 15:01
  • Yes, i did it :) Thanks a lot guys for your share and help :) – deveLost Sep 11 '14 at 15:12
  • Do you have an idea to restrict folders to show ? Because they are a lot of folders which are useless. – deveLost Sep 11 '14 at 15:51
  • how can I have an access to the download folder ? – deveLost Sep 11 '14 at 16:02
  • The download folder should be Environment.getExternalStorageDirectory() + "/download", i think. I forgot about the empty folders, because the phone I'm using here is rooted. I'd suggest to set the root-Directory to the SDcard (change isBaseDir(), SDcard should be Environment.getExternalStorageDirectory()) or maybe check if a Directory is empty before adding it to the adapter. – Kevin Gebhardt Sep 11 '14 at 16:44
  • mhh, I understand what you're saying, but, sincerily, currently, i don't understand exactly how your code works ^^ – deveLost Sep 11 '14 at 17:42
  • I tried to just set File dirTest = Environment.getExternalStorageDirectory(); but, I've again a lots of folder empty, and no one which contains my pdf downloaded. – deveLost Sep 11 '14 at 17:49
  • There is a problem but i don't find where :( I haven't file in my sdcare or storage, and in reality there are more folders with pdf files. – deveLost Sep 12 '14 at 12:06
  • That's odd. Sorry, but I can't help you before monday, important project here. You want to show only pdf-files, starting directory should be the download-folder and empty files should not be shown, right? I'll post working code on Monday... – Kevin Gebhardt Sep 12 '14 at 14:48
  • I don't understand why, but it seems there is a problem here : if (folder.listFiles() != null && folder.listFiles().length > 0){ Log.e("ok file", "ok" + folder.listFiles().length); fileList = new ArrayList(Arrays.asList(folder.listFiles())); }else{ fileList = new ArrayList(); } It returns always null, when I set the main path to Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) (and I'm sure, there are few pdf files) – deveLost Sep 13 '14 at 17:03