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 6353941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:29:50+00:00 2026-05-24T22:29:50+00:00

Suppose I have an Android block of code that looks something like this: String[]

  • 0

Suppose I have an Android block of code that looks something like this:

String[] proj = {MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media._ID};
int[] to = new int[] { R.id.artist_name };
Cursor musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, null, null, MediaStore.Audio.Media.ARTIST);
ListView musiclist = (ListView) findViewById(R.id.mylist);

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.songitem, musiccursor, proj, to);
musiclist.setAdapter(mAdapter);

But what I want, is this:

String selection = MediaStore.Audio.Media.FILE_PATH + " ilike '%audio%books%'";

String[] proj = {MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media._ID};
int[] to = new int[] { R.id.artist_name };
Cursor musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, selection, null, MediaStore.Audio.Media.ARTIST);
ListView musiclist = (ListView) findViewById(R.id.mylist);

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.songitem, musiccursor, proj, to);
musiclist.setAdapter(mAdapter);

The only problem, of course, is that FILE_PATH is not actually a column I can use, and as far as I can tell, no such column exists.

So I’m wondering:

  1. Is there a way to query only for music in a certain directory? If so, how?
  2. If that’s not an option, should I make a ListAdapter that filters by directory? If so, again, how would I go about in doing that?

Thanks for any advice.

  • 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-05-24T22:29:51+00:00Added an answer on May 24, 2026 at 10:29 pm

    OK, after many iterations of trying, I finally have an example that works and I thought I’d share it. My example queries the images MediaStore, then obtains the thumbnail for each image to display in a view. A few tweaks should provide you with the code needed to query the audio MediaStore instead. I am loading my images into a Gallery object, but that is not a requirement for this code to work:

    Make sure you have a Cursor and int for the column index defined at the class level so that the Gallery’s ImageAdapter has access to them:

    private Cursor cursor;
    private int columnIndex;
    

    First, obtain a cursor of image IDs located in the folder:

    Gallery g = (Gallery) findViewById(R.id.gallery);
    // request only the image ID to be returned
    String[] projection = {MediaStore.Images.Media._ID};
    // Create the cursor pointing to the SDCard
    cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection, 
            MediaStore.Images.Media.DATA + " like ? ",
            new String[] {"%myimagesfolder%"},  
            null);
    // Get the column index of the image ID
    columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
    g.setAdapter(new ImageAdapter(this));
    

    Then, in the ImageAdapter for the Gallery, obtain the thumbnail to display:

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView i = new ImageView(context);
        // Move cursor to current position
        cursor.moveToPosition(position);
        // Get the current value for the requested column
        int imageID = cursor.getInt(columnIndex);
        // obtain the image URI
        Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
        String url = uri.toString();
        // Set the content of the image based on the image URI
        int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
        Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
                        originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
        i.setImageBitmap(b);
        i.setLayoutParams(new Gallery.LayoutParams(150, 100));
        i.setScaleType(ImageView.ScaleType.FIT_XY);
        i.setBackgroundResource(mGalleryItemBackground);
        return i;
    }
    

    I guess the most important section of this code is the managedQuery that demonstrates how to use MediaStore queries to filter a list of image files in a specific folder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have my Android app's source code packaged this way: src/ my/ app/
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
suppose I have a string below. This is my string blah blah blah blah
Suppose i have a device that passes the minimum requirements for android OS ,
Suppose that, I have an android app that launches browser with some url supplied
Android 2.1 or greater Suppose I have two images that are the same size,
Suppose I have a Java class like this: public class Test { static {
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Suppose I have a table called Companies that has a DepartmentID column. There's also
I have the below code which is suppose to show a list of contact

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.