Reputation: 63
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 :(
Upvotes: 2
Views: 6436
Reputation: 1583
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());
Upvotes: 0
Reputation: 727
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`.Upvotes: 0
Reputation: 27539
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.
Upvotes: 1
Reputation: 677
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/
Upvotes: 1