I have an app for uploading files to a server using php! How can I implement file browser in my app to select which file to be uploaded! ? Please give me very simple example ! Or simple solution!
-
u can open dialog for files listed in sdcard and for upload watch this -->http://stackoverflow.com/questions/24731838/loop-to-upload-list-images-one-by-one/24894589#24894589 – KOTIOS Aug 01 '14 at 19:11
3 Answers
if you need to select any type of file there's no simple solution, you'll have to implement a file manager-similar functionality. Here are some tips and samples to get you started:
prerequisites: your have some basic understanding for how Android works; you know how to implement a custom ListView
- use
ListView
to display the files - parametrize your
Adapter
with anArrayList<File>
start with the root of external storage:
File root = Environment
.getExternalStorageDirectory();
the following method will list all files and subdirs in a directory:
public static ArrayList<File> getSubfiles(File root) {
File[] mFiles = root.listFiles();
ArrayList<File> files = new ArrayList<File>();
ArrayList<File> dirs = new ArrayList<File>();
ArrayList<File> allData = new ArrayList<File>();
for (int i = 0; i < myFiles.length; i++) {
if (!myFiles[i].isDirectory()) {
files.add(myFiles[i]);
} else {
dirs.add(myFiles[i]);
}
}
Collections.sort(files);
Collections.sort(dirs);
allData.addAll(dirs);
allData.addAll(files);
return allData;
}
using this method you can move "down" the file system by passing any directory to it. To move up, simply use getParentFile()
and pass the result to this method.
So you should always pass the result of this method to your Adapter, calling notifyDataSetChanged()
afterwards.
That's all, you have a very basic file viewer. Of course you will need to create some layouts and write a bit more of code, the above tips should help you to get started, since as was already mentioned nobody is going to write half of your app for you here on SO. If you have further questions/problems leave a comment and describe your problem.

- 11,485
- 17
- 93
- 141
There are so many solutions for this on google, and here you can't just ask for a full implementation and expect someone to write it here. Here are a couple of good results:
http://www.dreamincode.net/forums/topic/190013-creating-simple-file-chooser/
http://android-er.blogspot.pt/2010/01/implement-simple-file-explorer-in.html
Basically you will have a list dialog that will search for files and directories on your sdcard, then if it is a file (there are methods in File class to check if it is file or directory for example) then choose it and dismiss the dialog, or if it is a directory, change directory and refresh dialog with list of files and directories and so on.

- 3,062
- 2
- 23
- 33
If you only need to select the file path try the Android-Simple-File-Explorer-Library
First show the file explorer:
Intent intent = new Intent(CONTEXT, SimpleFileExplorerActivity);
startActivityForResult(intent, REQUEST_CODE);
And then receive the result:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if(data != null){
String selectedAbsolutePath = data.getStringExtra(SimpleFileExplorerActivity.ON_ACTIVITY_RESULT_KEY);
Toast.makeText(CONTEXT, selectedAbsolutePath, Toast.LENGTH_SHORT).show();
}
}