how to download image from server and store in internal storage using JSON in android -


i want download images server using json , storing in internal storage , after show image 1 one. have json format can body me how it??? json is:

    { "_id" : objectid("55b09029e56e5ecc1577f00e"), "user" : objectid("559a298d9969172f3ffeaa6d"),  "name" : "ddd",  "language" : "english",   "pages" :  [ {  "_id" : objectid("55b0902be56e5ecc1577f00f"),   "page_image" : [  { "image" : "images.png", "_id" : objectid("55b09032e56e5ecc1577f010") },  { "image" : "20140624_172041_fbhciha_sm.jpeg", "_id" : objectid("55b0903ce56e5ecc1577f011") },  { "image" : "673.jpg", "_id" : objectid("55b09042e56e5ecc1577f012") } ] } ], "__v" : 4 } 

1- add compile 'com.squareup.picasso:picasso:2.5.2'inside build.gradle or download jar file picasso

2- picasso.with(this) .load("your image url here") .into(target); if list can use above during traversing list(inside loop).

3-as target in above class displaying compile time error. put following code inner class.

private target target = new target() { @override  public void onbitmaploaded(final bitmap bitmap, picasso.loadedfrom from) {   new thread(new runnable() {        @override      public void run() {          file file = new file(environment.getexternalstoragedirectory().getpath() + "/image1.jpg");         try {            file.createnewfile();            fileoutputstream ostream = new fileoutputstream(file);            bitmap.compress(compressformat.jpeg, 80, ostream);            ostream.close();         } catch (exception e) {            e.printstacktrace();         }}   }).start(); }    @override     public void onbitmapfailed(drawable errordrawable) {}    @override    public void onprepareload(drawable placeholderdrawable) {   if (placeholderdrawable != null) {} }}; 

4-if still facing problem in understanding above code please refer following example. picasso - image downloading , caching library android

5- ` for(int = 0; < cons.length(); i++)

{     jsonobject c = cons.getjsonobject(i);     imgurl = c.getstring(image);     picasso.with(this)             .load(imgurl)             .into(new target() {                 @override                 public void onbitmaploaded(final bitmap bitmap, picasso.loadedfrom from) {                     new thread(new runnable() {                         @override                         public void run() {                              file file = new file(environment.getexternalstoragedirectory().getpath() + "/image1.jpg");                             try {                                 file.createnewfile();                                 fileoutputstream ostream = new fileoutputstream(file);                                 bitmap.compress(bitmap.compressformat.jpeg, 80, ostream);                                 ostream.close();                             } catch (exception e) {                                 e.printstacktrace();                             }}                     }).start();                 }                  @override                 public void onbitmapfailed(drawable errordrawable) {                  }                  @override                 public void onprepareload(drawable placeholderdrawable) {                  }             }); }` 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -