Skip to content Skip to sidebar Skip to footer

How To Get The Distinct Element From Mediastore By Java

I am trying to get the file names of all the audio files but I am getting same file names for multiple songs 1.I cannot use DISTINCT key word as I am getting the file names from D

Solution 1:

I want to get the Parent value as distinct not the repeating value .

Alright, you could use a HashSet<String> to maintain a list of seen MediaStore.Files.FileColumns.PARENT values.

Not sure what was wrong with the SQL approach, though.

HashSet<String> seenParents = new HashSet<String>();

if (audioCursor.moveToFirst()) {
    finalint fileparent = audioCursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.PARENT);
    do {
        Stringparent = audioCursor.getString(fileparent);

        Mediafileinfo info = new Mediafileinfo();
        // bla...
        info.setParent(parent);

        if (!seenParents.contains(parent)) { // prevents dups
            seenParents.add(parent);
            audioList.add(info);
        }

// end loop

Post a Comment for "How To Get The Distinct Element From Mediastore By Java"