Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8180849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:19:49+00:00 2026-06-07T00:19:49+00:00

I am trying to use a cursor with a managed query to filter media

  • 0

I am trying to use a cursor with a managed query to filter media content on the device

String[] dirs = new String[] {"%"+ dir + "%"};

String[] musicdata = { BaseColumns._ID,
        MediaColumns.DATA,
        MediaColumns.DISPLAY_NAME,
        MediaColumns.SIZE };

musiccursor = getActivity().getContentResolver().query(
        MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 
        musicdata, 
        MediaColumns.DATA + " like ? ", 
        dirs, 
        MediaColumns.DATA + " asc");

The where clause of the query uses a directory that is passed to it in order to filter for music within that folder and sub folders.

What I would like to do is also include a “not like” within the same query.

The reason for doing this is that the user has the ability to exclude a folder from a list view, and that is stored in an array and written to a file in order to retain the selection. I would like the cursor query to take these exclusions into account whilst still being linked to the folder that they pass through to it.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:19:51+00:00Added an answer on June 7, 2026 at 12:19 am

    In answer to my own query, here is the code:

             //Build the where clause
             StringBuilder where = new StringBuilder();
    
             //first add in all values from the exclusion array
             for (int i = 0; i < excludedFolders.size(); i++) {
             where.append(MediaColumns.DATA + " not like ? ");
             where.append(" AND ");
             }
             //then add in the final like clause, e.g. the folder the user selected
             where.append(MediaColumns.DATA + " like ? ");
    
             //convert it to a string
             String selection = where.toString();
    
             System.out.println(selection);
             ////////////////////////////////////////////////////////////////////////////////////////////
    
             //Build the arguments.  the array is set to the size of the exlcusion list, plus 1 for the fodler selected
             String[] dirs = new String[excludedFolders.size()+1]; 
             System.out.println(excludedFolders.size()+1);
             //first add in a value for each excluded folder
             for (int i = 0; i < excludedFolders.size(); i++) {
                    dirs[i] = "%" + excludedFolders.get(i) + "%";
                    System.out.println(i + " " + dirs[i]);
                }
             //add the argument value for the like element of the query 
             dirs[excludedFolders.size()]="%"+ dir + "%";
             System.out.println("excludedFolders.size() " + dirs[excludedFolders.size()]);  
             //start building the cursor
             String[] musicdata = { BaseColumns._ID,
                    MediaColumns.DATA,
                    MediaColumns.DISPLAY_NAME,
                    MediaColumns.SIZE };
             //run the query             
             musiccursor = getActivity().getContentResolver().query(
                        MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 
                        musicdata, 
                        selection,
                        dirs, 
                        MediaColumns.DATA+ " asc");
             //done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a cursor loop in MYSQL, but it's not working. I've
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
Trying to use records with the cursor and later index by table in the
I'm trying to use a ListAdapter to display the results of a Cursor. According
I am trying to use jqplot http://www.jqplot.com/tests/cursor-highlighter.php . I have successfully installed it in
I'm trying to use the following: String dbquery = Select * From stops where
So I'm trying to use a stored procedure via a cursor and callproc() but
I was trying to use the managedquery() in android to get back a cursor
I am trying to use this query upon my Android database, but it does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.