I have search much of questions related to my question..Is there anyway to store an image in internal memory and it should appear in the gallery as well?
-
If u r Interested to save image into sdcard then i will give you code for that. – Dipak Keshariya Sep 06 '11 at 04:56
-
thanks, but i already have set a function to save the image in the sdcard using this.. [getExternalStoragePublicDirectory](http://developer.android.com/reference/android/os/Environment.html) i want to know if i can save an image internally then the image would appear in the gallery – 4ucai Sep 13 '11 at 04:13
2 Answers
It's totally possible, I've done this before.
Before you are saving an image to the internal memory(or called app folder, etc.), you'd better set Context.MODE_WORLDREADABLE
. Although I set MODE_PRIVATE and can be read from gallery after I ran MediaScanner in my case, I recommend you set MODE_PRIVATE for the safety concern.
After you've saved your image to the internal memory, you can call MediaScanner like this:
// call media scanner to refresh gallery
MediaScannerConnection.scanFile(getApplicationContext(), new String[]{filePath}, null, new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
Log.i("MediaScanner", "Scanned " + path + ":");
Log.i("MediaScanner", "-> uri=" + uri);
}
});
Copy/Paste the code above should work. Then your image will appear to the gallery.
Reference of Context

- 1
- 1

- 7,001
- 5
- 54
- 80
You can treat your internal memory as a directory and write your file on it. Sample code coulde be found here. Loading image from memory is the same with reading binary image file from directory. Then you convert the file you have read to Bitmap using decodeByteArray and display on your gallery.
This is another example of saving image and display on screen (but this one is on webview instead of gallery).

- 1
- 1

- 138
- 1
- 4
-
thank you for the reply, i am using this code to save it internally in the – 4ucai Sep 13 '11 at 04:18
-
1thank you for the reply, i was able to save the image internally in the "data/data/com.example/files" directory.. I wanted it to be scanned so that it would appear in the phone gallery..I know images saved internally are private to your app. I did try scanning the image in the "data/data/com.example/files" directory using "MediaScannerConnection.scanFile". I am using an emulator without an sdcard attach, so i rather get exceptions or errors because the phone would create a thumb in gallery(which i think needs an external storage - sdcard to store it).. – 4ucai Sep 13 '11 at 04:27
-
I wanted to save the image internally for android phones without an sdcard mounted, where users are prompt to save the image and they can view the image in the gallery. I am also left wandering where camera taken pics are save in phones without sdcard. – 4ucai Sep 13 '11 at 05:18