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.