2

I create and save image in my Android app:

File dir = new File(Environment.getExternalStorageDirectory(), ".myappname/saved");
File imageFile = new File(dir, "IMG" + random() + ".jpg");
FileOutputStream out = new FileOutputStream(imageFile);
bi.compress(Bitmap.CompressFormat.JPEG, 100, out);

The images do not show up in the gallery -- even after reboots.

UPDATE: I only show part of the code! I also corrected the typos I introduced when writing the StackOverFlow message. The images save fine -- and I can view them -- they just don't show in Gallery. I just removed the dot from ".myappname" -- no the gallery shows the images. Strange. As I say below other apps save images in dot-folders and they show in gallery :(

user1436889
  • 63
  • 2
  • 9
  • I saw `fwdir` and I don't is this variable used in `imageFile`. Is this your real code? – ariefbayu Jun 05 '12 at 09:02
  • maybe you need to change code into: `File imageFile = new File(fwdir, "IMG" + random() + ".jpg");` – ariefbayu Jun 05 '12 at 09:04
  • I think that those answers will help you http://stackoverflow.com/questions/2170214/image-saved-to-sdcard-doesnt-appear-in-androids-gallery-app?rq=1 – BAZTED Dec 14 '12 at 13:43

4 Answers4

1

Save file on SDCARD/"some folde r" it will reflect in gallery,Gallery app doesn't shows images from private space. change below line of your code

 File fwdir = new File(Environment.getExternalStorageDirectory(), "myappname/saved");

Edit :- removed . from the directory name. as it is gonna be hidden folder.

AAnkit
  • 27,299
  • 12
  • 60
  • 71
1

You are creating a hidden folder by prefixing the folder name with a "." (period) the Media scanner will ignore this. At least that's the behavior I see when doing the same manually I have not tried it through code. Look at option 2 in this post http://www.makeuseof.com/tag/hide-private-picture-folders-gallery-android/

SidJ
  • 669
  • 12
  • 29
  • 1
    Thanks. I now realize it was the dot. I actually thought about this before posting this question, but since other image apps save their files in folders prefixed with "." and they show in gallery. Very strange. You don't know how to save your images in "." prefixed folders and still have them show in gallery? – user1436889 Jun 05 '12 at 09:35
  • I assume (and hope!) that's not possible, as an Android phone user I would be upset if I tried to hide a folder and it showed up in the gallery. I did this just a few days back on my phone :) – SidJ Jun 05 '12 at 09:46
0

your current problem is . appearing in the file path which makes it hidden but in some cases,
gallery does not populate images from private space
so use code


sendBroadcast(new Intent( Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
in your onDestroy() method`.
Check this link
http://rajareddypolam.wordpress.com/2013/01/29/android-saving-file-to-external-storage/
Karthik Rk
  • 707
  • 1
  • 10
  • 19
0

Write this Function in your Activity...

private void scanFile(String path) {

        MediaScannerConnection.scanFile(MainActivity.this,
                new String[] { path }, null,
                new MediaScannerConnection.OnScanCompletedListener() {

                    public void onScanCompleted(String path, Uri uri) {
                        Log.i("TAG", "Finished scanning " + path);
                    }
                });
    }

and then call this function where you save your image

scanFile(yourFile.getAbsolutePath());