private String buildMusicFoldersSelection(Cursor musicFoldersCursor){
  String mediaStoreSelection=MediaStore.Audio.Media.IS_MUSIC + "!=0 AND (";
  int folderPathColIndex=musicFoldersCursor.getColumnIndex(DBAccessHelper.FOLDER_PATH);
  int includeColIndex=musicFoldersCursor.getColumnIndex(DBAccessHelper.INCLUDE);
  for (int i=0; i < musicFoldersCursor.getCount(); i++) {
    musicFoldersCursor.moveToPosition(i);
    boolean include=musicFoldersCursor.getInt(includeColIndex) > 0;
    String likeClause;
    if (include)     likeClause=" LIKE ";
 else     likeClause=" NOT LIKE ";
    if (i != 0 && !include)     mediaStoreSelection+=" AND ";
 else     if (i != 0 && include)     mediaStoreSelection+=" OR ";
    mediaStoreSelection+=MediaStore.Audio.Media.DATA + likeClause + "'%"+ musicFoldersCursor.getString(folderPathColIndex)+ "/%'";
  }
  mediaStoreSelection+=")";
  return mediaStoreSelection;
}

private String buildMusicFoldersSelection ( Cursor musicFoldersCursor ) { String mediaStoreSelection = MediaStore . Audio . Media . IS_MUSIC + "!=0 AND (" ; int folderPathColIndex = musicFoldersCursor . getColumnIndex ( DBAccessHelper . FOLDER_PATH ) ; int includeColIndex = musicFoldersCursor . getColumnIndex ( DBAccessHelper . INCLUDE ) ; for ( int i = 0 ; i < musicFoldersCursor . getCount ( ) ; i ++ ) { musicFoldersCursor . moveToPosition ( i ) ; boolean include = musicFoldersCursor . getInt ( includeColIndex ) > 0 ; String likeClause ; if ( include ) likeClause = " LIKE " ; else likeClause = " NOT LIKE " ; if ( i != 0 && ! include ) mediaStoreSelection += " AND " ; else if ( i != 0 && include ) mediaStoreSelection += " OR " ; mediaStoreSelection += MediaStore . Audio . Media . DATA + likeClause + "'%" + musicFoldersCursor . getString ( folderPathColIndex ) + "/%'" ; } mediaStoreSelection += ")" ; return mediaStoreSelection ; }
constructs the selection string for limiting the mediastore query to specific music folders .
