android - Download and save image with Picasso -


i want download , save multiple images picasso library did not found how save on external storage... (sd)

picasso picasso = picasso.with(context)             .load(url)             .into(); 

is possible?

as far know not possible. picasso caches , downloads images asynchronously in separate thread.

i suggest using piccaso caching , showing pictures , using async task download , save images external storage.

   class downloadfilefromurl extends asynctask<string, string, string> {      /**      * before starting background thread      * */     @override     protected void onpreexecute() {         super.onpreexecute();         system.out.println("starting download");     }      /**      * downloading file in background thread      * */     @override     protected string doinbackground(string... f_url) {         int count;         try {             string root = environment.getexternalstoragedirectory().tostring();              system.out.println("downloading");             url url = new url(f_url[0]);              urlconnection conection = url.openconnection();             conection.connect();             // getting file length             int lenghtoffile = conection.getcontentlength();              // input stream read file - 8k buffer             inputstream input = new bufferedinputstream(url.openstream(), 8192);              // output stream write file              outputstream output = new fileoutputstream(root+"/downloadedfile.jpg");             byte data[] = new byte[1024];              long total = 0;             while ((count = input.read(data)) != -1) {                 total += count;                  // writing data file                 output.write(data, 0, count);              }              // flushing output             output.flush();              // closing streams             output.close();             input.close();          } catch (exception e) {             log.e("error: ", e.getmessage());         }          return null;     }        /**      * after completing background task      * **/     @override     protected void onpostexecute(string file_url) {         system.out.println("downloaded");     }  } 

you call above class using

    new downloadfilefromurl().execute(<the url want download from>); 

you need add below permissions manifest file

  <uses-permission android:name="android.permission.internet" />    <uses-permission android:name="android.permission.write_external_storage" /> 

hope helps


Comments