Yesterday I implemented functionality to retrieve list of songs from users device. It’s based on two components:
- Content resolver for making a query to find out some info about our songs
- Cursor for iterating through columns filled with out desirable info about songs
Why do we need Content Resolver? Can’t we just ask Content Provider for data? Basically, we don’t know which Content Provider we should ask about this specific data so Content Resolver does it for us. It’s used to pick the right Content Provider based on the URI that we have to provide while making a query.
URI for song query is like:
Making a query on our ContentResolver gives back in result a Cursor – an interface which returns collection of our query songs data. Now we can iterate through it to create and add instance of each song to songs list.
That’s it, we have collected info about our songs!