1

I'm making a project that opens a file and reads/writes data.

I'm doing this using the code below:

File file = new File(Environment.getExternalStorageDirectory().getPath() 
                   + "/Project/Application/" + fileName);

It's working. The problem is I only can get this file if its path is the specific 'Project/Application' directory.

How can I allow the user to navigate into the device file system and find the file himself?

Dave Newton
  • 158,873
  • 26
  • 254
  • 302

1 Answers1

0

Android does not have a file chooser by itself. The only file list that Android can show natively is a ringtone list.

Here you have some solutions:

  • Load the file list into an array and show a dialog showing the file list, as you can read here: Choose File Dialog. Using this method you can detect when the user clicks an item that is a folder and then show a new dialog with the files inside that folder, so the user can navigate easily.

  • Here is a good answer to your question that has a built-in file chooser just in case that the user does not have one installed: Android file chooser

  • And also here you have a good library: https://code.google.com/p/android-filechooser/

Community
  • 1
  • 1
Jorge Fuentes González
  • 11,568
  • 4
  • 44
  • 64
  • Sorry for answering late. I was studying your message. It helped me a lot. I got this link http://www.dreamincode.net/forums/topic/190013-creating-simple-file-chooser/ and could get what I wanted. Now I can navigate and see (by Toast) the path of a file. The problem now is: How to get this path in the activity that calls the File Chooser? Do you have any ideia? Thank you again! – user2520990 Jun 28 '13 at 17:12
  • So you are starting the file chooser as a new activity, is'nt it? You can start the activity with `startActivityForResult` instead of `startActivity`. Is a bit long to explain here, check this post: http://stackoverflow.com/questions/10407159/android-how-to-manage-start-activity-for-result?answertab=votes#tab-top Instead of toasting the file path, use `setResult` and `finish()` the activity. The first activity will receive the `onActivityResult` call when the second activity finishes. – Jorge Fuentes González Jun 28 '13 at 17:19