Android - How to upload an image and use it as a new resource?

I want to download an image from a remote server and use it as a resource. Is it possible? How can i do this?

+7
android image resources download
source share
4 answers

Yes, you cannot upload it as a resource file. You can upload and store images on an SDCard or database and upload them there ...

To check how to upload images to SDCard, refer to this link.

http://snippets.dzone.com/posts/show/8685#related

Then you can download it from your sdcard as follows

http://android-er.blogspot.com/2010/01/how-to-display-jpg-in-sdcard-on.html

This is how you store and retrieve images from ur db

http://www.helloandroid.com/tutorials/store-imagesfiles-database

+7
source share

Is it possible?

You can upload an image. However, this will not be a "resource". Resources are packaged inside the APK and cannot be changed or added at runtime.

+7
source share

How I did it:

private class ImgDownload extends AsyncTask { private String requestUrl; private ImageView view; private Bitmap pic; private ImgDownload(String requestUrl, ImageView view) { this.requestUrl = requestUrl; this.view = view; } @Override protected Object doInBackground(Object... objects) { try { URL url = new URL(requestUrl); URLConnection conn = url.openConnection(); pic = BitmapFactory.decodeStream(conn.getInputStream()); } catch (Exception ex) { } return null; } @Override protected void onPostExecute(Object o) { view.setImageBitmap(pic); } } 
+7
source share

This issue was discussed and resolved by Gilles Debunn, an engineer at the Android group, in a blog post on Multithreading for Performance.

It already uses AsyncTask internally. Since it was created for Android, it can upload an image and install it directly on ImageView with the following two lines of code:

 ImageDownloader imageDownloader = new ImageDownloader(); imageDownloader.download(url, imageView); 

The ImageDownloader class can be found in the linked repository .

+4
source share

All Articles