android - Captured multiple photos from camera does not set on imageview - Samsung S3 issue -


its been 5 days , no 1 help!! please can me

i have problem , persists specially samsumg s3 phones only. trying take 4 images camera service of android.

the problem when trying other phones same code works fine, shows problem samsung s3 phone.

what trying have 4 imageview's, on every imageview's onclick can open camera service or gallery service according users choice. once image being clicked or selected, image set on particular imageview clicked.

so can set 4 images 1 one. works fine other phone , other samsung phones seems have problem samsung s3.

could please me out.

here code taking images on imageview.

my oncreate method

public class add_image extends activity {  imageview imgview1, imgview2, imgview3, imgview4; private static int result_load_image = 1; private static final int camera_image_capture = 0; private static final int pick_from_gallery = 2; int camera_pic_request = 1337; string sd_card_image_path = null; byte b[]; string largeimagepath = ""; uri urilargeimage; uri urithumbnailimage; private static final int og = 4; int flag = 0, orientation; string bal, picturepath, bal1, bal2, bal3, bal4; int flagg = 0; cursor mycursor, cursor1; bitmap thumbnail = null;  textview t5, t6, t7, t8; // sharedpreferences pic1, pic2, pic3, pic4;  button btn;  @override protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     setcontentview(r.layout.image);     imgview1 = (imageview) this.findviewbyid(r.id.imageview1);     imgview1.setonclicklistener(click_img1);      imgview2 = (imageview) this.findviewbyid(r.id.imageview2);     imgview2.setonclicklistener(click_img2);      imgview3 = (imageview) this.findviewbyid(r.id.imageview3);     imgview3.setonclicklistener(click_img3);      imgview4 = (imageview) this.findviewbyid(r.id.imageview4);     imgview4.setonclicklistener(click_img4);     t5 = (textview) findviewbyid(r.id.textview5);     t5.setvisibility(view.visible);     t6 = (textview) findviewbyid(r.id.textview6);     t6.setvisibility(view.visible);     t7 = (textview) findviewbyid(r.id.textview7);     t7.setvisibility(view.visible);     t8 = (textview) findviewbyid(r.id.textview8);     t8.setvisibility(view.visible);      btn = (button) findviewbyid(r.id.button1);     btn.setonclicklistener(btn_click);      if (savedinstancestate != null) {          bitmap carpic;         string b1 = savedinstancestate.getstring("message");         // toast.maketext(this, "savedyeah"+b1, toast.length_long).show();         bitmapfactory.options opts = new bitmapfactory.options();         opts.insamplesize = og;          carpic = bitmapfactory.decodefile((b1), opts);         system.gc();         if (carpic != null) {              imagecam(carpic);         }      }  } 

different button clicks

public view.onclicklistener btn_click = new view.onclicklistener() {      @override     public void onclick(view v) {         intent intent = new intent(add_image.this, add.class);         startactivity(intent);      } };  private view.onclicklistener click_img1 = new view.onclicklistener() {      @override     public void onclick(view v) {         flag = 1;         opennewgamedialog();      } }; private view.onclicklistener click_img2 = new view.onclicklistener() {      @override     public void onclick(view v) {         flag = 2;         opennewgamedialog();      } }; private view.onclicklistener click_img3 = new view.onclicklistener() {      @override     public void onclick(view v) {         flag = 3;         opennewgamedialog();      } }; private view.onclicklistener click_img4 = new view.onclicklistener() {      @override     public void onclick(view v) {         flag = 4;         opennewgamedialog();      } }; 

my opennewgamedialog() method check manufacturer , camera service

string[] b = { "camera", "gallery", "delete image" };  private void opennewgamedialog() {     new alertdialog.builder(this).setitems(b,             new dialoginterface.onclicklistener() {                 public void onclick(dialoginterface dialoginterface, int i) {                     if (i == 0) {                         string bx1 = android.os.build.manufacturer;                          if (bx1.equalsignorecase("samsung")) {                             // toast.maketext(getapplicationcontext(),                             // "device man"+bx1, toast.length_long).show();                             intent intent = new intent(                                     mediastore.action_image_capture);                             startactivityforresult(intent,                                     camera_image_capture);                          } else {                             intent cameraintent = new intent(                                     android.provider.mediastore.action_image_capture);                             startactivityforresult(cameraintent,                                     camera_pic_request);                         }                     }                      else if (i == 1) {                          intent intent = new intent(intent.action_pick);                         intent.settype("image/*");                         startactivityforresult(intent, result_load_image);                     } else if (i == 2) {                         if (flag == 1) {                             imgview1.setimagedrawable(null);                             t5.setvisibility(view.visible);                         }                         if (flag == 2) {                             imgview2.setimagedrawable(null);                             t7.setvisibility(view.visible);                         }                         if (flag == 3) {                             imgview3.setimagedrawable(null);                             t6.setvisibility(view.visible);                         }                         if (flag == 4) {                             imgview4.setimagedrawable(null);                             t8.setvisibility(view.visible);                         }                      }                  }             }).show(); } 

imagecam() method set images imageview

public void imagecam(bitmap thumbnail) {      bitmap photo = thumbnail;     bytearrayoutputstream bos = new bytearrayoutputstream();     photo.compress(bitmap.compressformat.jpeg, 70, bos);      b = bos.tobytearray();     bal = base64.encodebytes(b);     // imageview imageview = (imageview) findviewbyid(r.id.imageview1);      string bx1 = android.os.build.manufacturer;     if (bx1.equalsignorecase("samsung") && flagg == 0) {      }     if (flag == 1) {         bal1 = bal;          t5.setvisibility(view.gone);         imgview1.setimagebitmap(photo);         // toast.maketext(getapplicationcontext(), "image1=" + bal1,         // toast.length_long).show();     } else if (flag == 2) {         bal2 = bal;          t7.setvisibility(view.gone);         imgview2.setimagebitmap(photo);         // toast.maketext(getapplicationcontext(), "image2=" + bal2,         // toast.length_long).show();     } else if (flag == 3) {         bal3 = bal;          t6.setvisibility(view.gone);         imgview3.setimagebitmap(photo);         // toast.maketext(getapplicationcontext(), "image3=" + bal3,         // toast.length_long).show();     } else if (flag == 4) {         bal4 = bal;          t8.setvisibility(view.gone);         imgview4.setimagebitmap(photo);         // toast.maketext(getapplicationcontext(), "image4=" + bal4,         // toast.length_long).show();     }      add ad = new add();     ad.image_save(bal1, bal2, bal3, bal4);     // flag=0;  }  @override public void onsaveinstancestate(bundle outstate) {     super.onsaveinstancestate(outstate);     outstate.putstring("message", largeimagepath);     outstate.putstring("gallerymessage", picturepath);  } 

onactivityresult() method

protected void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     if (requestcode == camera_image_capture             && resultcode == activity.result_ok) {         flagg = 0;         // describe columns you'd have returned. selecting         // thumbnails location gives both thumbnail image id,         // original image id         string[] projection = {                 mediastore.images.thumbnails._id, // columns want                 mediastore.images.thumbnails.image_id,                 mediastore.images.thumbnails.kind,                 mediastore.images.thumbnails.data };         string selection = mediastore.images.thumbnails.kind + "=" + // select                                                                         //                                                                         // mini's                 mediastore.images.thumbnails.mini_kind;          string sort = mediastore.images.thumbnails._id + " desc";          // @ moment, bit of hack, i'm returning         // images, , taking latest one. there better way         // narrow down think clause         // selection variable         mycursor = this.managedquery(                 mediastore.images.thumbnails.external_content_uri,                 projection, selection, null, sort);          long imageid = 0l;         long thumbnailimageid = 0l;         string thumbnailpath = "";          try {              mycursor.movetofirst();             imageid = mycursor                     .getlong(mycursor                             .getcolumnindexorthrow(mediastore.images.thumbnails.image_id));             thumbnailimageid = mycursor                     .getlong(mycursor                             .getcolumnindexorthrow(mediastore.images.thumbnails._id));             thumbnailpath = mycursor                     .getstring(mycursor                             .getcolumnindexorthrow(mediastore.images.thumbnails.data));         } {             // mycursor.close();         }          // create new cursor obtain file path large image          string[] largefileprojection = {                 mediastore.images.imagecolumns._id,                 mediastore.images.imagecolumns.data };          string largefilesort = mediastore.images.imagecolumns._id + " desc";         mycursor = this.managedquery(                 mediastore.images.media.external_content_uri,                 largefileprojection, null, null, largefilesort);         largeimagepath = "";          try {             mycursor.movetofirst();              // give yo uthe file path location of             // image.             largeimagepath = mycursor                     .getstring(mycursor                             .getcolumnindexorthrow(mediastore.images.imagecolumns.data));         } {              // mycursor.close();         }         // these 2 uri's you'll interested in. give         // handle actual images         urilargeimage = uri.withappendedpath(                 mediastore.images.media.external_content_uri,                 string.valueof(imageid));         urithumbnailimage = uri.withappendedpath(                 mediastore.images.thumbnails.external_content_uri,                 string.valueof(thumbnailimageid));          // i've left out remaining code, assign uri's         // own objects anyways...         // toast.maketext(this, ""+largeimagepath,         // toast.length_long).show();         // toast.maketext(this, ""+urilargeimage, toast.length_long).show();         // toast.maketext(this, ""+urithumbnailimage,         // toast.length_long).show();          if (largeimagepath != null) {             toast.maketext(this, "large yes" + largeimagepath,                     toast.length_long).show();              bitmapfactory.options opts = new bitmapfactory.options();             opts.insamplesize = og;             // thumbnail = (bitmapfactory.decodefile(picturepath));             thumbnail = bitmapfactory.decodefile((largeimagepath), opts);             bitmap bitmap = thumbnail;             system.gc();              try {                 exifinterface exif = new exifinterface(largeimagepath);                  orientation = exif.getattributeint(                         exifinterface.tag_orientation, 1);                  log.e("exifinteface .........", "rotation =" + orientation);                  // exif.setattribute(exifinterface.orientation_rotate_90,                 // 90);                  log.e("orientation", "" + orientation);                 matrix m = new matrix();                  if ((orientation == exifinterface.orientation_rotate_180)) {                     m.postrotate(180);                     // m.postscale((float) bm.getwidth(), (float)                     // bm.getheight());                     // if(m.prerotate(90)){                     log.e("in orientation", "" + orientation);                     bitmap = bitmap.createbitmap(thumbnail, 0, 0,                             thumbnail.getwidth(), thumbnail.getheight(), m,                             true);                  } else if (orientation == exifinterface.orientation_rotate_90) {                     m.postrotate(90);                     log.e("in orientation", "" + orientation);                     bitmap = bitmap.createbitmap(thumbnail, 0, 0,                             thumbnail.getwidth(), thumbnail.getheight(), m,                             true);                  } else if (orientation == exifinterface.orientation_rotate_270) {                     m.postrotate(270);                     log.e("in orientation", "" + orientation);                     bitmap = bitmap.createbitmap(thumbnail, 0, 0,                             thumbnail.getwidth(), thumbnail.getheight(), m,                             true);                  }             } catch (exception e) {              }              if (thumbnail != null) {                 // toast.maketext(this, "try without saved instance",                 // toast.length_long).show();                 imagecam(bitmap);             }          }         if (urilargeimage != null) {              // toast.maketext(this, ""+urilargeimage,             // toast.length_long).show();          }         if (urithumbnailimage != null) {              // toast.maketext(this, ""+urithumbnailimage,             // toast.length_long).show();          }      }     if (requestcode == 1337 && resultcode == result_ok) {         flagg = 0;         bundle extras = data.getextras();         // if (extras!=null){         if (extras.keyset().contains("data")) {              bitmapfactory.options options = new bitmapfactory.options();             // options.insamplesize = 1;             // options.inpurgeable = true;             // options.ininputshareable = true;             thumbnail = (bitmap) extras.get("data");             // image(thumbnail);             if (thumbnail != null) {                 // toast.maketext(this, "yes thumbnail",                 // toast.length_long).show();                 bitmapfactory.options opt = new bitmapfactory.options();                 // options.insamplesize = 1;                 // options.inpurgeable = true;                 // options.ininputshareable = true;                 thumbnail = (bitmap) extras.get("data");                 imagecam(thumbnail);             }          } else {              uri imageuri = getintent().getdata();             imageview imageview = (imageview) findviewbyid(r.id.imageview1);             imageview.setimageuri(imageuri);              if (imageuri != null) {                 // toast.maketext(this, "yes image uri",                 // toast.length_long).show();              }              // toast.maketext(createprofile.this, "picture not taken",             // toast.length_long).show();         }      }     if (requestcode == result_load_image && resultcode == result_ok             && null != data) {         uri selectedimage = data.getdata();          flagg = 1;          string[] filepathcolumn = { mediastore.images.media.data };         cursor1 = getcontentresolver().query(selectedimage, filepathcolumn,                 null, null, null);         cursor1.movetofirst();         int columnindex = cursor1.getcolumnindex(filepathcolumn[0]);         string picturepath = cursor1.getstring(columnindex);         // cursor.close();         bitmapfactory.options opts = new bitmapfactory.options();         opts.insamplesize = og;         // thumbnail = (bitmapfactory.decodefile(picturepath));         thumbnail = bitmapfactory.decodefile((picturepath), opts);         system.gc();         bitmap bitmap = thumbnail;          try {             exifinterface exif = new exifinterface(picturepath);              orientation = exif.getattributeint(                     exifinterface.tag_orientation, 1);              log.e("exifinteface .........", "rotation =" + orientation);              // exif.setattribute(exifinterface.orientation_rotate_90, 90);              log.e("orientation", "" + orientation);             matrix m = new matrix();              if ((orientation == exifinterface.orientation_rotate_180)) {                 m.postrotate(180);                 // m.postscale((float) bm.getwidth(), (float)                 // bm.getheight());                 // if(m.prerotate(90)){                 log.e("in orientation", "" + orientation);                 bitmap = bitmap.createbitmap(thumbnail, 0, 0,                         thumbnail.getwidth(), thumbnail.getheight(), m,                         true);              } else if (orientation == exifinterface.orientation_rotate_90) {                 m.postrotate(90);                 log.e("in orientation", "" + orientation);                 bitmap = bitmap.createbitmap(thumbnail, 0, 0,                         thumbnail.getwidth(), thumbnail.getheight(), m,                         true);              } else if (orientation == exifinterface.orientation_rotate_270) {                 m.postrotate(270);                 log.e("in orientation", "" + orientation);                 bitmap = bitmap.createbitmap(thumbnail, 0, 0,                         thumbnail.getwidth(), thumbnail.getheight(), m,                         true);              }         } catch (exception e) {          }          if (thumbnail != null) {             imagecam(bitmap);         } else {             toast.maketext(this, "please select different picture",                     toast.length_long).show();         }      }      else {         // imgview.setbackgroundresource(r.drawable.bbtb);     }  }  } 


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -