ios85
ios85

Reputation: 2134

Using downloaded images in an Android Application

I want to download PDF's and images into my app, essentially it will call a JSON web service that returns the link to the PDF, link to the image, and the title. It will download the image and PDF and save them. Then it will display the PDF's and images with the title. My only question is how do I deal with images? They cant be saved to APK since it is locked. The images are high enough resolution that they can scaled down to fit all the other densities, should I just use the large image, and let the activity scale it down when it uses it. Or should I implement an image scaler during the retrieval process?

Eventually the PDF's and images would be loaded into the APK. How would I check the assets folder to remove the images, would I just need to call a service that runs when the Application First starts to check for the files in the assets folder then remove them if they are present?

Upvotes: 0

Views: 53

Answers (1)

Srikanth Roopa
Srikanth Roopa

Reputation: 1790

Sample code for your reference where u can download Images from the web.Its better to store Images in asset folder than Internal Memory and resize the images for good performance.U can delete the folder before making web service call and load new set images.

if (Utility.isWifiPresent()
                    || Utility.isMobileConnectionPresent()) {
                URL url = new URL(fileUrl);
                InputStream iStream = url.openConnection().getInputStream();// .read(data)
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                byte[] tmpArray = new byte[1024];
                int nRead;
                while ((nRead = iStream.read(tmpArray, 0, tmpArray.length)) != -1) {
                    buffer.write(tmpArray, 0, nRead);
                }
                buffer.flush();
                data = buffer.toByteArray();
                FileOutputStream fOut = null;
        //path to store

                    fOut = Utility.getFileOutputStreamForCloud(
                            sdcardFolderPath, fileUrl);
                }
                fOut.write(data);
                fOut.flush();
                fOut.close();

Upvotes: 0

Related Questions