I am fetching Genre list from media content Provider of android using CursorLoder class. below is my cursor query to fetch the list of Genre.
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// currently filtering.
Uri baseUri;
baseUri = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI;
String[] STAR = { "*" };
return new CursorLoader(getActivity(), baseUri, STAR, null, null, null );
}
Now, i got all the genre list from the media content provider but the problem with the data i got. I also got the genre name which is created before but right now i don't have song in it.
I only want the genre that have songs in it, not the genre name that dont have songs in it.
Can anyone help me in that?
UPDATE
I can able to fetch all the Genre and its Song using below code...
private void getGenresList() {
//-------------------------------------
int index;
long genreId;
int count;
Uri uri;
Cursor genrecursor;
Cursor tempcursor;
String[] proj1 = {MediaStore.Audio.Genres.NAME, MediaStore.Audio.Genres._ID};
String[] proj2={MediaStore.Audio.Media.DISPLAY_NAME};
genrecursor=getActivity().getContentResolver().query(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI,proj1,null, null, null);
if(genrecursor.moveToFirst())
{
do{
index = genrecursor.getColumnIndexOrThrow(MediaStore.Audio.Genres.NAME);
System.out.println("GENRE NAME: "+genrecursor.getString(index));
System.out.println("======================================");
index = genrecursor.getColumnIndexOrThrow(MediaStore.Audio.Genres._ID);
genreId=Long.parseLong(genrecursor.getString(index));
uri = MediaStore.Audio.Genres.Members.getContentUri("external", genreId);
tempcursor = getActivity().getContentResolver().query(uri, proj2, null,null,null);
System.out.println("Total Songs: "+tempcursor.getCount());
if(tempcursor.moveToFirst())
{
do{
index=tempcursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
System.out.println(" Song Name: "+tempcursor.getString(index));
}while(tempcursor.moveToNext());
}
System.out.println("======================================");
}while(genrecursor.moveToNext());
}
//-------------------------------------
}
But, i must have to use two query, one for fetching all the genre and second for filter data with the Genre which have songs. Even i would like to use that in the CursorLoader so i am wonder wonder about how to do that.
Hope you got proper idea what i want with this question.