java - Trouble with Android Camera -


i have code have been experimenting see can camera device. following code works, have issues cannot seem solve.

  1. the first call never works. first time running code onpicturetaken callback never called, file never written. camera goes through other steps, including making fake shutter noise.

  2. i can't seem set picture size other whatever defaults to. if try set else, code stops working. same above, camera goes through motions, onpicturetaken callback never called.

  3. when pictures saved dcim folder, taken pictures not show in default 'photos' app on phone, unless reboot phone.

  4. is there way through code disable shutter noise?

sorry, code little messy because experiment.

also, code executed in broadcastreceiver

    @override public void onreceive(context context, intent intent) {     // todo auto-generated method stub       if(intent.getaction().equals(take_picture_intent))     {           toast.maketext(context, "test", toast.length_long).show();                   system.out.println("got intent");                      try                     {                         camera camera = camera.open();                          system.out.println("camera opened");                          parameters params = camera.getparameters();                         params.set("flash-mode", "off");                         params.set("focus-mode", "infinity");                         params.set("jpeg-quality", "100");                         //params.setpicturesize(2592, 1952);                          string str = params.get("picture-size" + "-values");                         system.out.println(str);                          string size = str.split(",")[0];                         system.out.println(size);                          //params.set("picture-size", size);                          camera.setparameters(params);                           system.out.println("camera parameters set");                            camera.startpreview();                         system.out.println("camera preview started");                           camera.autofocus(new autofocuscallbackimpl());                       }                     catch(exception ex)                     {                         system.out.println("camera fail, skip");                         return ;                     }       }//if     }//onreceive   private void takepicture(camera camera) {     camera.takepicture(new camera.shuttercallback() {          @override         public void onshutter() {             // todo auto-generated method stub              system.out.println("camera shutter callback");         }     }      , null,          new camera.picturecallback() {                  public void onpicturetaken(byte[] imagedata, camera c) {                     //c.release();                      system.out.println("camera callback");                      fileoutputstream outstream = null;                     try {                          system.out.println("start callback");                         file esd = environment.getexternalstoragedirectory();                          outstream = new fileoutputstream(esd.getabsolutepath() + string.format(                                 "/dcim/%d.jpg", system.currenttimemillis()));                          outstream.write(imagedata);                         outstream.close();                         system.out.println( "onpicturetaken - wrote bytes: " + imagedata.length);                     } catch (filenotfoundexception e) {                         e.printstacktrace();                            system.out.println("file not found exception");                     } catch (ioexception e) {                         e.printstacktrace();                            system.out.println("io exception");                     } {                           system.out.println("finally");                           c.release();                     }                  }             }          );     //camera.release(); }//take picture  private class autofocuscallbackimpl implements camera.autofocuscallback {     @override     public void onautofocus(boolean success, camera camera) {         //bisautofocused = success; //update flag used in onkeydown()         system.out.println("inside autofocus callback. autofocused="+success);         //play autofocus sound         //mediaplayer.create(cameraactivity.this, r.raw.auto_focus).start();          if(success)         {             system.out.println("auto focus succeded");         }         else         {             system.out.println("auto focus failed");         }          takepicture(camera);         system.out.println("called take picture");      }  }//autofocuscallback 

1.first of put camera logic out of broadcast receiver & put seprate activity.

2.

when pictures saved dcim folder, taken pictures not show in default 'photos' app on phone, unless reboot phone.

because mediascanner needs called rescan images/changes once take photo. when u reboot phone mediascanner scans media & finds new images. isuue should check out mediascanner.

3.follow android camera tutorial & camera api

-thanks


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -