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.
Drag the app icon onto another app. This will create a new folder, and open your folder's contents.
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.
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.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With