Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create application specific folder in android gallery?

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.

like image 368
Harshal Kshatriya Avatar asked Dec 11 '13 15:12

Harshal Kshatriya


People also ask

How do I create app folders in Android 11?

Drag the app icon onto another app. This will create a new folder, and open your folder's contents.

How do I exclude folders from gallery?

While entering a name for your folder, just add “.” (period) before the folder name. So, if I was going to create a folder named “HideMe,” I would name it “. HideMe.” Note the dot that I added before the folder name and not the period at the end of the sentence. Then tap the “OK” button and let it create the folder.


2 Answers

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.

like image 114
Yaroslav Mytkalyk Avatar answered Oct 21 '22 19:10

Yaroslav Mytkalyk


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.

like image 2
CommonsWare Avatar answered Oct 21 '22 18:10

CommonsWare