Woodsy
Woodsy

Reputation: 3377

Specifying a Gallery folder

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?

Upvotes: 6

Views: 2828

Answers (2)

bluefalcon
bluefalcon

Reputation: 4235

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 :)

Upvotes: 3

Moyshe
Moyshe

Reputation: 1122

If you are able to convert your image to simple stream, you can use Android predefined methods: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

Upvotes: 0

Related Questions