Android hardware camera fire intent after onPictureTaken -


i have implemented own camera preview layout , functionality. anyway, when press button take picture calls onpicturetaken method, intent not fired. intent declared correctly in manifest file.

here code , hope knows here in order fire intent.

public class takepicture extends activity { private preview mpreview; private camera mcamera; private int numberofcameras; private int defaultcameraid; private context context;  autofocuscallback myautofocuscallback = new autofocuscallback() {     @override     public void onautofocus(boolean arg0, camera arg1) {         // buttontakepicture.setenabled(true);     } };  picturecallback mypicturecallback_jpg = new picturecallback() {     @override     public void onpicturetaken(byte[] arg0, camera arg1) {         //savepicture(arg0);          intent ia = new intent(context, previewphoto.class);         ia.putextra("groupid", 1);         ia.putextra("image", arg0);         startactivity(ia);     } };  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     requestwindowfeature(window.feature_left_icon);     setfeaturedrawableresource(window.feature_left_icon,             r.drawable.zzz_logo);     context = this;      mpreview = new preview(this);     setcontentview(mpreview);     layoutinflater controlinflater = layoutinflater.from(getbasecontext());     view viewcontrol = controlinflater.inflate(r.layout.camera_control,             null);     layoutparams layoutparamscontrol = new layoutparams(             layoutparams.fill_parent, layoutparams.fill_parent);     this.addcontentview(viewcontrol, layoutparamscontrol);      numberofcameras = camera.getnumberofcameras();     camerainfo camerainfo = new camerainfo();     (int = 0; < numberofcameras; i++) {         camera.getcamerainfo(i, camerainfo);         if (camerainfo.facing == camerainfo.camera_facing_back) {             defaultcameraid = i;         }     }      button buttontakepicture = (button) findviewbyid(r.id.takepicture);     buttontakepicture.setonclicklistener(new button.onclicklistener() {         @override         public void onclick(view arg0) {             mcamera.takepicture(null, null,                     mypicturecallback_jpg);         }     }); }  @override protected void onresume() {     super.onresume();      mcamera = camera.open(defaultcameraid);     mpreview.setcamera(mcamera); }  @override protected void onpause() {     super.onpause();      if (mcamera != null) {         mpreview.setcamera(null);         mcamera.release();         mcamera = null;     } }   public void determinedisplayorientation() {         camerainfo camerainfo = new camerainfo();         camera.getcamerainfo(defaultcameraid, camerainfo);          int rotation = this.getwindowmanager().getdefaultdisplay().getrotation();         int degrees  = 0;          switch (rotation) {             case surface.rotation_0:                 degrees = 0;                 break;              case surface.rotation_90:                 degrees = 90;                 break;              case surface.rotation_180:                 degrees = 180;                 break;              case surface.rotation_270:                 degrees = 270;                 break;         }          int displayorientation;          if (camerainfo.facing == camera.camerainfo.camera_facing_front) {             displayorientation = (camerainfo.orientation + degrees) % 360;             displayorientation = (360 - displayorientation) % 360;         } else {             displayorientation = (camerainfo.orientation - degrees + 360) % 360;         }          mcamera.setdisplayorientation(displayorientation);     }  private void savepicture(byte[] data) {     file picturefiledir = getdir();     if (!picturefiledir.exists() && !picturefiledir.mkdirs()) {         toast.maketext(context, "can't create directory save image.",           toast.length_long).show();         return;     }      simpledateformat dateformat = new simpledateformat("yyyymmddhhmmss");     string date = dateformat.format(new date());     string photofile = "picture_" + date + ".jpg";     string filename = picturefiledir.getpath() + file.separator + photofile;     file picturefile = new file(filename);      try {       fileoutputstream fos = new fileoutputstream(picturefile);       fos.write(data);       fos.close();       toast.maketext(context, "new image saved:" + photofile,           toast.length_long).show();     } catch (exception error) {       toast.maketext(context, "image not saved.",           toast.length_long).show();     } }  private file getdir() {     file sddir = environment       .getexternalstoragepublicdirectory(environment.directory_pictures);     return new file(sddir, "captoom");   }  class preview extends viewgroup implements surfaceholder.callback {     private final string tag = "preview";      surfaceview msurfaceview;     surfaceholder mholder;     size mpreviewsize;     list<size> msupportedpreviewsizes;     camera mcamera;      preview(context context) {         super(context);         msurfaceview = new surfaceview(context);         addview(msurfaceview);          mholder = msurfaceview.getholder();         mholder.addcallback(this);         mholder.settype(surfaceholder.surface_type_push_buffers);          msurfaceview.setonclicklistener(new linearlayout.onclicklistener() {             @override             public void onclick(view arg0) {                 //buttontakepicture.setenabled(false);                 mcamera.autofocus(myautofocuscallback);             }         });     }      public void setcamera(camera camera) {         mcamera = camera;         if (mcamera != null) {             msupportedpreviewsizes = mcamera.getparameters()                     .getsupportedpreviewsizes();             requestlayout();         }     }      public void switchcamera(camera camera) {         setcamera(camera);         //determinedisplayorientation();          try {             camera.setpreviewdisplay(mholder);         } catch (ioexception exception) {             log.e(tag, "ioexception caused setpreviewdisplay()", exception);         }          camera.parameters parameters = camera.getparameters();         parameters.setpreviewsize(mpreviewsize.width, mpreviewsize.height);         requestlayout();         camera.setparameters(parameters);     }      @override     protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {         final int width = resolvesize(getsuggestedminimumwidth(),                 widthmeasurespec);         final int height = resolvesize(getsuggestedminimumheight(),                 heightmeasurespec);         setmeasureddimension(width, height);          if (msupportedpreviewsizes != null) {             mpreviewsize = getoptimalpreviewsize(msupportedpreviewsizes, width,                     height);         }     }      @override     protected void onlayout(boolean changed, int l, int t, int r, int b) {         if (changed && getchildcount() > 0) {             final view child = getchildat(0);              final int width = r - l;             final int height = b - t;              int previewwidth = width;             int previewheight = height;             if (mpreviewsize != null) {                 previewwidth = mpreviewsize.width;                 previewheight = mpreviewsize.height;             }              if (width * previewheight > height * previewwidth) {                 final int scaledchildwidth = previewwidth * height                         / previewheight;                 child.layout((width - scaledchildwidth) / 2, 0,                         (width + scaledchildwidth) / 2, height);             } else {                 final int scaledchildheight = previewheight * width                         / previewwidth;                 child.layout(0, (height - scaledchildheight) / 2, width,                         (height + scaledchildheight) / 2);             }         }     }      public void surfacecreated(surfaceholder holder) {         try {             if (mcamera != null) {                 mcamera.setpreviewdisplay(holder);             }         } catch (ioexception exception) {             log.e(tag, "ioexception caused setpreviewdisplay()", exception);         }     }      public void surfacedestroyed(surfaceholder holder) {         if (mcamera != null) {             mcamera.stoppreview();         }     }      private size getoptimalpreviewsize(list<size> sizes, int w, int h) {         final double aspect_tolerance = 0.1;         double targetratio = (double) w / h;         if (sizes == null)             return null;          size optimalsize = null;         double mindiff = double.max_value;          int targetheight = h;          (size size : sizes) {             double ratio = (double) size.width / size.height;             if (math.abs(ratio - targetratio) > aspect_tolerance)                 continue;             if (math.abs(size.height - targetheight) < mindiff) {                 optimalsize = size;                 mindiff = math.abs(size.height - targetheight);             }         }          if (optimalsize == null) {             mindiff = double.max_value;             (size size : sizes) {                 if (math.abs(size.height - targetheight) < mindiff) {                     optimalsize = size;                     mindiff = math.abs(size.height - targetheight);                 }             }         }         return optimalsize;     }      public void surfacechanged(surfaceholder holder, int format, int w, int h) {         camera.parameters parameters = mcamera.getparameters();         parameters.setpreviewsize(mpreviewsize.width, mpreviewsize.height);         requestlayout();          mcamera.setparameters(parameters);         mcamera.startpreview();     } } } 

the line ia.putextra("image", arg0) causing error failed binder transaction. must pass image path, not byte[] of data new intent :)


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -