Android explorer
<p>I am developing a classified booking android application. In it I need filesystem exploring functionality that enables the user to select images from the SD card.</p>

<p>I currently have the fallowing code:</p>

<pre><code>public class AndroidExplorer extends ListActivity
{
    private List&lt;String&gt;    item    = null;
    private List&lt;String&gt;    path    = null;
    private String          root    = "/";
    private TextView        myPath;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myPath = (TextView) findViewById(R.id.path);
        try
        {
            getDir(root);
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    private void getDir(String dirPath) throws IOException
    {
        myPath.setText("Location: " + dirPath);

        item = new ArrayList&lt;String&gt;();
        path = new ArrayList&lt;String&gt;();

        File f = new File(dirPath);
        File[] files = f.listFiles();

        if (!dirPath.equals(root))
        {
            item.add(root);
            path.add(root);

            item.add("../");
            path.add(f.getParent());
        }

        for (int i = 0; i &lt; files.length; i++)
        {
            File file = files[i];
            String FileExt = file.getName();
            path.add(file.getPath());

            if (file.isDirectory())
                item.add(file.getName() + "/");
            // else if(FileExt.endsWith(".jpg"))
            // item.add(FileExt);
        }

        ArrayAdapter&lt;String&gt; fileList = new ArrayAdapter&lt;String&gt;(this, R.layout.row, item);
        setListAdapter(fileList);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id)
    {
        File file = new File(path.get(position));

        if (file.isDirectory())
        {
            if (file.canRead())
                try
                {
                    getDir(path.get(position));
                }
                catch (IOException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            else
            {
                new AlertDialog.Builder(this).setIcon(R.drawable.icon)
                        .setTitle("[" + file.getName() + "] folder can't be read!")
                        .setPositiveButton("OK", new DialogInterface.OnClickListener()
                        {

                            // @Override
                            public void onClick(DialogInterface dialog, int which)
                            {
                                // TODO Auto-generated method stub
                            }
                        }).show();
            }
        }
        else
        {
            new AlertDialog.Builder(this).setIcon(R.drawable.icon).setTitle("[" + file.getPath() + "]")
                    .setPositiveButton("OK", new DialogInterface.OnClickListener()
                    {

                        // @Override
                        public void onClick(DialogInterface dialog, int which)
                        {
                            // TODO Auto-generated method stub
                        }
                    }).show();
        }
    }
}
</code></pre>
