Android Programming: Where to Start for Creating a Simple File Browser

Android Programming: Where To Start For Creating A Simple File Browser?

If you're actually more interested in learning to write your own, I'd suggest taking a good long read through the File class documentation. That's where you're going to be doing most of the work.

In the case of SD cards/other external storage for Android, you'll want to first check to ensure that the external storage is mounted and available before trying to read it, using the Environment class:

String extState = Environment.getExternalStorageState();
//you may also want to add (...|| Environment.MEDIA_MOUNTED_READ_ONLY)
//if you are only interested in reading the filesystem
if(!extState.equals(Environment.MEDIA_MOUNTED)) {
//handle error here
}
else {
//do your file work here
}

Once you've determined the proper state of the external storage, a simple way to start is to use File's listFiles() method, like so:

//there is also getRootDirectory(), getDataDirectory(), etc. in the docs
File sd = Environment.getExternalStorageDirectory();
//This will return an array with all the Files (directories and files)
//in the external storage folder
File[] sdDirList = sd.listFiles();

You can then start using FileFilters to narrow down your results:

FileFilter filterDirectoriesOnly = new FileFilter() {
public boolean accept(File file) {
return file.isDirectory();
}
};
File[] sdDirectories = sd.listFiles(filterDirectoriesOnly);

From there on, just read through the docs to find the type of thing you're looking to do with it, and then you can work on tying these into list adapters, etc.

Hope this helps!

Efficient implementation of File Explorer - Android

Keep a single activity no question about it !

When a user clicks an item you build your data-source based on the newly selected path. Make sure to distinct between files and directories. Then simply call notifyDataSetChanged and thats it !

To query the file system there are two ways:

  1. The easy - use Java File.listFiles()
  2. The hard - run shell command Runtime.getRuntime().exec( "ls -la" ) and parse response.

There are many open source projects on github for the subject. Example:

Amaze File Manager

How to use intent for choosing file browser to select file

You can use something like this:

    ....  
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, YOUR_RESULT_CODE);
....

But I really doubt that you can set a filter third-party file browsers.
Or you can try to use this file dialog: http://code.google.com/p/android-file-dialog/

How to use file browser in android

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.



Related Topics



Leave a reply



Submit