I want to copy a remote image, for example "http://example.com/example.jpg" to the android user phone built gallery...How can I do it?
-
Gallery folders do not exists. The Gallery is only an app which can show you all pictures residing on your device. So you can put that picture in any folder you want. – greenapps Nov 23 '14 at 11:12
2 Answers
To that, you should download the image and save it in internal memory.
You can download the image by yourself:
public static Bitmap getBitmap(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Bitmap d = BitmapFactory.decodeStream(is);
is.close();
return d;
} catch (Exception e) {
return null;
}
}
Code from here But you will have memory problems with large images. I strongly recommended you to use a build library like Android Universal Image Loader or Picasso from square

- 1
- 1

- 2,229
- 1
- 33
- 56
-
First it should be downloaded to external memory as that is where Gallery app has access. Second it is a very bad idea to make a Bitmap out if a .jpg where the jpg data can directly be saved to file. – greenapps Nov 23 '14 at 11:36
Here you can find an example of how to use the Android DownloadManager to download your file.
The destination path can be determined using the contants defined in the Environment class. Constant DIRECTORY_DCIM points to the parent directory under which all Activities can create a custom folder where they store their images. You could make your own child folder as destination folder
When your image finishes downloading, you will notice that it will not be listed in the default gallery application, this is because Android builds an index with all the media files and is still unaware of your new downloaded image. This index is updated each time you boot your Android device, but since it's a bit unconvienient to reboot your device each time a file is added, you can also codewise inform the indexing service that a new file is created and needs indexing using this piece of code:
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);
This scanning should also occur after a file has been erased.

- 184
- 4