Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // get the content resolver instance
- ContentResolver contentResolver = getContentResolver();
- // the column of the year
- final String year = MediaStore.Audio.AudioColumns.YEAR;
- // create the string array with the returned values, there is the trick
- // we use the DISTINCT before the name of the column
- String[] values = new String[] { "DISTINCT " + year };
- // execute the query
- // we also check not to get null values
- Cursor cursor = contentResolver
- .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values,
- year + " not null", null,
- MediaStore.Audio.AudioColumns.YEAR);
- // for each returned row we printed using android Logging fuctions
- // we use loggat with tag distinct to see the result
- // also you can show the results in the gui of your app
- while (cursor.moveToNext()) {
- Log.d("distinct", "year " + cursor.getString(0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement