I'm trying to save images onto an SD card but some of the images cannot load into 2 different gallery apps. When I transfer the images to my PC, I can see that all the ones that don't load on my phone, kind of didn't download. They have these green or gray gradients half way up the image. I guess they didn't finish downloading.
This code from my PC program works flawlessly, but when ported to android, I'm getting issues. I was reading about it online, and I thought maybe I need to use the openFileOutput and set the MODE_WORLD_READABLE. If this is a possible issue, can someone please explain how to use Context to get it to work?
I was saving images to a custom folder on my phone, but then I changed it to the Pictures folder. Same issue
ReadableByteChannel rbc2 = Channels.newChannel(link2.openStream());//Gets the image FileOutputStream fos2 = new FileOutputStream(Methods.getMainDir() + File.separator + galleryName + File.separator + outputFileName);//The output of the file name fos2.getChannel().transferFrom(rbc2, 0, 1 << 24); fos2.flush(); fos2.close();
Best Answer thatguyandrew1992 , 07 July 2013 - 18:44
Well, it was something to do with that code I was using for downloading. I changed my code to the following and the issue seems to be gone! I'll keep testing, and if it works, I mark this as a solution
URL url = new URL("http://www.yahoo.com/image_to_read.jpg");
InputStream in = new BufferedInputStream(url.openStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte buf = new byte;
int n = 0;
out.write(buf, 0, n);
byte response = out.toByteArray();
FileOutputStream fos = new FileOutputStream();