Many android apps need a File browser to help users work with files in their device. In this tutorial we going to create a simple File Explorer.
Here is a result of this tutorial:
This project is developed in Eclipse 4.2.0.
1. Make application interface: The main layout of this app demo is very simple layout. It have one text view, one edit text and one button.
We show all items(folder and file) on File-explorer under a custom list view and here is the code xml layout for each row in list:
Each row have three text views, the first one shows the name of item, the second text view shows the number of item if that row contains a folder and show the capacity if it is a file, the last one shows the last modifying date of this item. The result is:
2. Java Code
2.1. Code for Main Activity, when we click on the button, we will open a new activity:
The result from FileChoose is a name of file.
2.2. The new activity is FileChoose extends ListActivity, here is all codes of FileChoose Activity:
2.3. Create FileArrayAdapter for Listview above:
2.4. Finally we create file item.java for item object:
3.1. Run application
3.2. Click on a button
3.3. After click on a file in File-explorer, show this file name on edit text on Main activity
You can download all source codes of this tutorial from here.