Question

I'm building android application "XYZ" in which users will be storing media such as images and videos. Therefore, I would like to create a folder in android gallery named "XYZ" and store all the media specific to the application in "XYZ". How do I achieve it?

Currently, I'm able to store the media on sdcard and on scanning the media files, they show up in "images" folder, in android gallery.

Was it helpful?

Solution

I guess the proper way of storing your images accessible by galleries is writing the files to this directory.

static final String appDirectoryName = "XYZ";
static final File imageRoot = new File(Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_PICTURES), appDirectoryName);

And for videos

static final File videoRoot = new File(Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_MOVIES), appDirectoryName);

And to create an image

imageRoot.mkdirs();
final File image = new File(imageRoot, "image1.jpg");
// open OutputStream and write the file

If you add some files and open the gallery you should see album "XYZ". Note that you will not see the album if the directory is empty.

And about your words

Currently, I'm able to store the media on sdcard and on scanning the media files, they show up in "images" folder, in android gallery.

The representation depends on the Gallery app you use. The default Android gallery should create "Albums" named after the folder the media files are in.

Edit: you will not see newly created image if you don't run media scanner or add it to MediaStore database.

OTHER TIPS

There are > 1 billion Android devices, representing thousands of device models, with hundreds of different "gallery" apps (pre-installed or user-installed). There is no requirement for any "gallery" app to have the concept of folders, let alone for third-party developers to control those folders.

Hence, there is no general way of achieving your objective, other than to write your own such app.

If you are able to store the videos and images in external storage like SD card, I assume you know how to use "FILES"

therefore you just need to name the location you want to save in and create it (if it doesnt exist)

something like:

File file = new File(Environment.getExternalStorageDirectory() +"/XYZ/");  

if(!file.exists())     //check if file already exists
{
    file.mkdirs();     //if not, create it
}

this is your Directory Folder, and you can save in it what ever you want.

something like:

File imageFile = new File(file.toString() + "image" + ".jpg");

This will create an image file called "image.jpg" in the directory XYZ.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top