Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying a Gallery folder

Tags:

android

I have some code that takes a screen capture from the app and saves it to the SD card and makes it available in the Gallery. The problem is it saves it with the camera pictures when you look for it in the gallery. I would rather it save under the download folder or create an app specific folder (PicSay does something like this) where all the screen shots will be accessible to the user. Currently, I'm using the following to save to the camera gallery:

MediaStore.Images.Media.insertImage(getContentResolver(), imagePath, fileName, desc);

How can you get it to save to a different location other than Camera?

like image 321
Woodsy Avatar asked Oct 21 '11 17:10

Woodsy


People also ask

How to exclude folder from gallery?

Enter “. nomedia” as the file name and tap on “OK.” The Android Gallery app does not scan for media files in the folders that have a file named “. nomedia.” The file just tells the app that there are no media files here in this folder to be included in the gallery.

How do I get a list of images in a specific folder on Android?

You can use below code to get all images from specific folder. 1) First you need to define File object to get the storage and appened the name of the folder you want to read. File folder = new File(Environment. getExternalStorageDirectory().

What is the gallery path in Android?

"gallery" is an app, not a location. Your pictures on your phone could be located anywhere, depending on how they got on your phone. Your camera will store its images at "/DCIM/camera", or a similar location. Social media apps may download photos into the "/download" folder or a folder under the app's name.

How do I open gallery on Android?

To open gallery: (This should be in your activity class.) public OnClickListener btnChoosePhotoPressed = new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent. ACTION_PICK, android.


1 Answers

You can use the normal Java API's to save the image file to any place you want in the external storage directory.. (Hint - using the FileOutputStream)

The only problem you need to solve is to tell Andriod that you have added a new content, so update the content databse. Which the gallery can use to display the images to the user.

So create a new ContentValue and just insert it into the ContentResolver. You can get a handle to the ContentResolver using the API getContentResolver()

The ContentValue contains relevant information like name of the image, absolute path to it, date it was created, size of the file etc., not all of these mandatory, go through the Android Doc and pick off values that are irrelevant to you.

ContentValues values = new ContentValues(7);

values.put(Images.Media.TITLE, title);
values.put(Images.Media.DISPLAY_NAME, fileName);
values.put(Images.Media.DATE_TAKEN, currTime);
values.put(Images.Media.MIME_TYPE, "image/jpeg");
values.put(Images.Media.ORIENTATION, 0);
values.put(Images.Media.DATA, filePath);
values.put(Images.Media.SIZE, jpegData.length);

contentResolver.insert(STORAGE_URI, values);

And voila, the Gallery will show the image where it is placed :)

like image 179
bluefalcon Avatar answered Oct 29 '22 21:10

bluefalcon