save - Saving an image to sd card from android pager -


i have pager activity in android application need save images according there position in pager. managed saving part when iam in first image click save saves second image same second image save third dont know whats wrong code! `

enter code here  public boolean onoptionsitemselected(menuitem item)  {     // handle item selection     if (item.getitemid()==r.id.menufinale)      {          imageview imageview = (imageview) findviewbyid(r.id.image_one);         imageview.setdrawingcacheenabled(true);         bitmap bitmap = imageview.getdrawingcache();         file root = environment.getexternalstoragedirectory();         mediastore.images.media.insertimage(getcontentresolver(), bitmap, "my pic" ,"saved gallery");         file file = new file(root.getabsolutepath()+"/dcim/camera/img.jpg");         try          {             file.createnewfile();             fileoutputstream ostream = new fileoutputstream(file);             bitmap.compress(compressformat.jpeg, 100, ostream);             ostream.close();         }          catch (exception e)          {             e.printstacktrace();         }            return true;     }         else  {                 return super.onoptionsitemselected(item);             }     } 

try thing below :

 button=(button)vi.findviewbyid(r.id.button_save);          button.setonclicklistener(new onclicklistener() {    private bitmap bm;   private string prefs_name; public void onclick(view arg0) {     string root = environment.getexternalstoragedirectory().tostring();        file mydir = new file(root + "/saved_images");        if(!mydir.exists()){            mydir.mkdirs();}        bm = bitmapfactory.decoderesource( mcontext.getresources(), images[itempos]);          holder.image.setimagebitmap(bm);          sharedpreferences savednumber = mcontext.getsharedpreferences(prefs_name, 0);          int lastsavednumber = savednumber.getint("lastsavednumber",0);          lastsavednumber++;          string fname = "image-"+lastsavednumber+".png";           file file = new file (mydir, fname);          if (file.exists ()) {file.delete (); }          try {          fileoutputstream out = new fileoutputstream(file);          bm.compress(bitmap.compressformat.png, 100, out);//your bitmap resouce          out.flush();          out.close(); }          catch (exception e) {          e.printstacktrace();          }           sharedpreferences savenumber = mcontext.getapplicationcontext().getsharedpreferences(prefs_name, 0);          sharedpreferences.editor editorset = savenumber.edit();          editorset.putint("lastsavednumber",lastsavednumber);          editorset.commit();           toast.maketext(mcontext, "saved", toast.length_short). show();}}); 

hope you.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -