0

I have a Bitmap saved in the directory: Environment.getExternalStorageDirectory()+ File.separator + "Images" in a subdirectory. With a fileManager i can find the image and open it. But in the Gallery of the Smartphone i can't find the Image. How can i get it there?

L3n95
  • 1,505
  • 3
  • 25
  • 49

2 Answers2

1

To be make you file known by the Gallery you need to call the MediaScanner:

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);

See also: https://www.grokkingandroid.com/adding-files-to-androids-media-library-using-the-mediascanner/

1

You can actually directly access the Pictures directory. To do this, use

getExternalStoragePublicDirectory(String type)

, where type is equal to Environment.DIRECTORY_PICTURES. See http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory%28java.lang.String%29 for more info.

That's cleaner than supposing that pictures are always stored in a directory called "Images"...

Now to force the Gallery to register the change, look at https://stackoverflow.com/a/15837638/2984973 . To quote the answer, you want to broadcast an intent specifying your new picture, likewise:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(myNewFile)));
Community
  • 1
  • 1
Sehor06
  • 33
  • 4