Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. // get the content resolver instance
  2.         ContentResolver contentResolver = getContentResolver();
  3.  
  4.         // the column of the year
  5.         final String year = MediaStore.Audio.AudioColumns.YEAR;
  6.  
  7.         // create the string array with the returned values, there is the trick
  8.         // we use the DISTINCT before the name of the column
  9.         String[] values = new String[] { "DISTINCT " + year };
  10.  
  11.         // execute the query
  12.         // we also check not to get null values
  13.         Cursor cursor = contentResolver
  14.                 .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values,
  15.                         year + " not null", null,
  16.                         MediaStore.Audio.AudioColumns.YEAR);
  17.  
  18.         // for each returned row we printed using android Logging fuctions
  19.         // we use loggat with tag distinct to see the result
  20.         // also you can show the results in the gui of your app
  21.         while (cursor.moveToNext()) {
  22.             Log.d("distinct", "year " + cursor.getString(0));
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement