Save Image From URL in a Specific Location in Android -
i'm creating app downloads images off internet! images downloaded without problem! problem downloaded in unknown folder,and downloaded images not seen in gallery app! how can download images in specific gallery folder visible in gallery well? in advance!
download method:
downloadmanager dm = (downloadmanager) getsystemservice(context.download_service); uri uri = uri.parse(url); downloadmanager.request request = new downloadmanager.request(uri); request.setdescription("downloading wallpaper").settitle("downloading"); request.setnotificationvisibility(downloadmanager.request.visibility_visible_notify_completed); mydownloadreference = dm.enqueue(request); toast.maketext(wallpaper.this, "downloading..", toast.length_short).show(); }
image url bitmap
try { url url = new url("http://...."); bitmap image = bitmapfactory.decodestream(url.openconnection().getinputstream()); } catch(ioexception e) { system.out.println(e); } public void saveimagetoexternal(string imgname, bitmap bm) throws ioexception { //create path save image file path = environment.getexternalstoragepublicdirectory(environment.directory_pictures+appfolder); //creates app specific folder path.mkdirs(); file imagefile = new file(path, imgname+".png"); // imagename.png fileoutputstream out = new fileoutputstream(imagefile); try{ bm.compress(bitmap.compressformat.png, 100, out); // compress image out.flush(); out.close(); // tell media scanner new file // available user. mediascannerconnection.scanfile(context,new string[] { imagefile.getabsolutepath() }, null,new mediascannerconnection.onscancompletedlistener() { public void onscancompleted(string path, uri uri) { log.i("externalstorage", "scanned " + path + ":"); log.i("externalstorage", "-> uri=" + uri); } }); } catch(exception e) { throw new ioexception(); } }
Comments
Post a Comment