save image in android -


this code saving images in sd card if , if not exist. don't know how read it. can me please.

this download file method:

public static string downloadfile(string neturl,  string name ) {            try {                     //need uses permission write_external_storage                  bytearraybuffer baf = null;                 long starttime = 0;                  //get directory (a file object) sd card                     file savepath=new file(environment.getexternalstoragedirectory().getpath()+"/postimages/");                     string ext="jpg";                 url url = new url(neturl);                   //create specific file image storage:                 file file = new file(savepath, name + "." + ext);                 boolean success = true;                 if (!savepath.exists()) {                     success = savepath.mkdir();                 }                 if (success) {                     if(file.createnewfile())                       {                         file.createnewfile();                       //write bitmap                     log.i("file existence", "file not exist!!!!!!!!!!!");            /* open connection url. */                 urlconnection ucon = url.openconnection();                  inputstream = ucon.getinputstream();                  bufferedinputstream bis = new bufferedinputstream(is);                 starttime = system.currenttimemillis();                   baf = new bytearraybuffer(5000);                 int current = 0;                 while ((current = bis.read()) != -1) {                     baf.append((byte) current);                 }                       /* convert bytes read string. */                 fileoutputstream fos = new fileoutputstream(file);                 fos.write(baf.tobytearray());                 fos.flush();                 fos.close();                 log.d("downloadmanager", "download ready in" + ((system.currenttimemillis() - starttime) / 1000) + " sec");                  return file.getabsolutepath();                       }//end of create file if not exists                  }//end of if success               } catch (exception exx) {                 if (exx.getmessage() != null) {                   } else {                   }              }              return null;         } 

try this,

uri uri = uri.parse("file:///sdcard/temporary_file.jpg");

img.setimageuri(uri);


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -