title: How to get list of all music files from android phone
body: <p>I created an app that scans music files on the mobile phone. It scans the music files if I scan the folder <strong>/sdcard/Music</strong> but it doesn't scan the mp3 file when I write <strong>/sdcard</strong>. It is working fine. But it is not working on some devices, the application crashes maybe because of that path not present on that phone what should I do?</p>
  
  <p>CODE</p>
  
  <pre><code>public class SongsManager {
  
  // SDCard Path
    String MEDIA_PATH = new String("/sdcard/Music");
   private ArrayList&lt;HashMap&lt;String, String&gt;&gt; songsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
  // Constructor
  public SongsManager() {
  
  }
  
  /**
   * Function to read all mp3 files from sdcard
   * and store the details in ArrayList
   */ public ArrayList&lt;HashMap&lt;String, String&gt;&gt; getPlayList(){
         File home = new File(MEDIA_PATH);
  
  
      if (home.listFiles(new FileExtensionFilter()).length &gt; 0) {
          for (File file : home.listFiles(new FileExtensionFilter())) {
              HashMap&lt;String, String&gt; song = new HashMap&lt;String, String&gt;();
              song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
              song.put("songPath", file.getPath());
              // Adding each song to SongList
              songsList.add(song);
          }
      }
      // return songs list array
      return songsList;
  }
  
  class FileExtensionFilter implements FilenameFilter {
      public boolean accept(File dir, String name) {
          return (name.endsWith(".mp3") || name.endsWith(".MP3"));
      }
  }
  </code></pre>
  
  <p>}</p>