Displaying mp3 files from all folders and subfolders present in SD card
<p>I am trying to set a ring tone for my alarm application. For this i need to display all songs with .mp3 extension present in various folders and sub folders in SD card.</p>

<p>I want only the .mp3 files to be displayed and not any of the folders/ sub folders. I already have a coding where songs are displayed from SD card and not from within the sub folders.  All coding given retrieve songs only from a specific folder which i dont need. I need every mp3 song that exists in sd card.</p>

<pre><code>public class Mp3filterActivity extends Activity{
    final String MEDIA_PATH = new String("/sdcard/");

    public void onCreate(Bundle savedInstanceState){
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         ListView listsong =(ListView)findViewById(R.id.songlist);

        ArrayList&lt;String&gt; mp3list = new ArrayList&lt;String&gt;();
        mp3list=mp3select();
        Toast.makeText(this, "mp3files" +mp3list, Toast.LENGTH_LONG).show();

       ArrayAdapter&lt;String&gt; listAdapter=new ArrayAdapter&lt;String&gt;(Mp3filterActivity.this,android.R.layout.simple_list_item_1,mp3list);
        listsong.setAdapter(listAdapter);

    }

    public ArrayList&lt;String&gt; mp3select(){
        File home = new File(MEDIA_PATH);
        ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
        //if (home.isDirectory())

        if (home.listFiles(new FileExtensionFilter()).length &gt; 0) 
        {
            for (File file : home.listFiles(new FileExtensionFilter())) 
            {
                   list.add(file.getName().substring(0, (file.getName().length() - 4)));        
                }
        }
        return list;
    }

    class FileExtensionFilter implements FilenameFilter 
    {
        public boolean accept(File dir, String name) {
            return (name.endsWith(".mp3") ||name.endsWith(".MP3"));
        }
    }
}
</code></pre>
