tags:

views:

41

answers:

1

I am using the Gallery3D-Code but want it to only display images from a sub-folder on the SD, not all of the images that are stored on it. To do this, I tried to change

public static final Uri STORAGE_URI = Images.Media.EXTERNAL_CONTENT_URI;

to

public static final Uri STORAGE_URI = Uri.fromFile(new File(ROOT_DIR));,

where String ROOT_DIR = Environment.getExternalStorageDirectory().toString() + "/mySubDirectory";

but I guess this is transforming a content://-Uri to a file://-Uri and this may be a problem?

In any case, it doesn't work :-(! Instead of just showing images from the ROOT_DIR-directory and its sub-directories, it shows no images at all ("Gallery empty"). Could anyone point me in the right direction as to what I am doing wrong?

A: 

Edited

I'm assuming you mean the Open Source code for Gallery3D. Instead of changing the content provider Uri in STORAGE_URI, have you looked at changing CAMERA_IMAGE_BUCKET_NAME in ImageManager.java and/or CAMERA_BUCKET_NAME in LocalDataSource.java?

I see several places where getExternalStorageDirectory() is mentioned.

Old Answer

Try using withAppendedPath(Uri baseUri, String pathSegment) to add your subdirectory to the Uri. Perhaps something like this would work for you:

Uri.withAppendedPath(Images.Media.EXTERNAL_CONTENT_URI, 
    Uri.encode("mySubDirectory"));
Brian
Thanks, Brian. Unfortunately, this doesn't work either. I have only seen `withAppendedPath` being used with a String as the path, e.g. `Uri u2 = Uri.withAppendedPath(u, "1");` which makes u2: `content://media/external/images/media/1`, I don't think an actual Uri-encoded path is a valid extension of the base-Uri? I guess I need to filter the `MediaStore.Images.Media.DATA`-Column by filepath...somehow?
Nick
I had suggested using `Uri.encode()` since the documentation for `pathSegment` said it took an "encoded path segment to append". I've edited my answer with another suggestion.
Brian
Thanks for your edit. I already tried changing the camera-bucket to my directory (rather than leaving it at `/DCIM`), but that piece of code just seems to handle the camera-label and -icon on the respective camera-folder (i.e. whether to show a "Camera"-icon or a normal "Folder"-icon).
Nick