2

I want to implement an image picker using the default android Gallery. To launch this gallery i use this function:

private void launchGallery() {
  Intent intent = new Intent(
    Intent.ACTION_PICK,
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  startActivityForResult(intent, GALLERY_TOKEN);

}

This all works great, the gallery is launched and i catch the result.

The problem however is that the gallery is launched in the top level view of all albums. My App has created a subdirectory in /mnt/sdcard/Pictures/App/Album1 Ofcourse Album1 can be a wildcard of names. My assignment is to launch this gallery straight into the selected folder instead of the top level view.

I tried the following but it doesnt work, could anyone help me with this problem?

private void launchGallery() {
    Intent intent = new Intent(Intent.ACTION_PICK);
    File file = new File("/mnt/sdcard/Pictures/App/Album/");
    intent.setDataAndType(Uri.fromFile(file), "image/*");
    startActivityForResult(intent, GALLERY_TOKEN);
}

Thanks alot!

-- EDIT --

Currently im looking into Bucket_ID as defined by the mediastore. This should hold the ID of the parent directory.

int bucketIdIndex = cursor
     .getColumnIndexOrThrow(Images.ImageColumns.BUCKET_ID);

For my file this prints a negative number.

03-30 13:40:21.923: D/ImageHelper(2208): Data: /mnt/sdcard/Pictures/App/bbb/gvv/376.jpg

Result is:

03-30 13:40:21.942: D/ImageHelper(2208): bucketId: -1014163439

As defined by several articles i use this code to construct my URI:

uri = MediaStore.Images.Media.INTERNAL_CONTENT_URI.buildUpon()
            .appendQueryParameter("bucketId", bucketId).build();

Then i launch it:

Intent intent = new Intent(Intent.ACTION_PICK,
            ImageHelper.getDirectoryUri(this, mImageId));
startActivityForResult(intent, GALLERY_TOKEN);

However this does not work. Just launches the top view of the gallery.

Sam_Appstrakt
  • 111
  • 1
  • 6
  • http://stackoverflow.com/questions/4019534/gallery-with-folder-filter possible duplicate – Th0rndike Mar 30 '12 at 08:41
  • Using that mediascanner provides me an Uri, however the gallery refuses to launch into the specified folder. (I scan folder /sdcard/pictures/app/ for example The returned Uri is: content://media/external/file/10540 – Sam_Appstrakt Mar 30 '12 at 09:20
  • like how we can fetch image/video data using bucket-id(folder-id)...how we can do same thing for audio files. – CoDe Nov 10 '12 at 08:36
  • 1
    Did you find out the solution? – Nam Vu Mar 17 '13 at 02:40

0 Answers0