Adding images to the gallery
Asked Answered
M

1

7

My application store images in a private folder /sdcard/Android/data/com.mypackage.myapp/files/. I want to add those picture to the gallery. I tried adding them to the media store but it creates a folder for each folder I have in my private directory. I want more control on the name/structure of the albums. I think I'm supposed to use a content provider for this, but I'm not sure what to do next. The snippet I'm using is the following :

    ContentValues values = new ContentValues(4);
    long current = System.currentTimeMillis();
    values.put(MediaStore.Images.Media.TITLE, file.getName());
    values.put(MediaStore.Images.Media.DATE_ADDED, (int) (current / 1000));
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpg");
    values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
    ContentResolver contentResolver = context.getContentResolver();

    Uri base = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    Uri newUri = contentResolver.insert(base, values);

    // Notify the media application on the device
    context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));

This works great but doesn't give me control on the folder structure. How can I add my images to the gallery with a folder structure different from the file structure like google does with "picasa" (and how to put a custom icon for folders like the picasa icon below)

enter image description here

Masochism answered 18/4, 2014 at 18:50 Comment(0)
K
0

Did you try adding the artist field:

values.put(MediaStore.Images.Media.ARTIST, "YourApp");

I'm not sure that you can designate the icon, so it will always be a folder. Picasa support is built in.

Kathleenkathlene answered 24/4, 2014 at 12:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.