android - how to capture an image with camera and save in a folder -


in application need capture images , save them in folder option rename it. , sorry bad english ..... , tried not work, saves 1 image snap more photos, why? :d

public class testpress extends activity  {     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.prova);         final string direct = this.getintent().getstringextra("key");          // todo auto-generated method stub         button p = (button) findviewbyid(r.id.button2);         p.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                   intent camera= new intent(android.provider.mediastore.action_image_capture);                  uri urisavedimage=uri.fromfile(new file("/sdcard/cameratest/flashcropped.png"));                 camera.putextra(mediastore.extra_output, urisavedimage);                 startactivityforresult(camera, 1);              }         });         button np = (button) findviewbyid(r.id.button3);         np.setonclicklistener(new onclicklistener() {             @override             public void onclick(view v) {                  intent next = new intent(press.this, cameraactivity.class);                 startactivity(next);             }         });     } } 

    private void dotakephotoaction() {      intent intent = new intent(mediastore.action_image_capture);     // 创建目录     file filedir = new file(environment.getexternalstoragedirectory()             + "/zuijiao");     if (!filedir.exists()) {         filedir.mkdirs();     }     // 拍照后的路径     imagepath = environment.getexternalstoragedirectory() + "/zuijiao/"             + system.currenttimemillis() + ".jpg";     carmerafile = new file(imagepath);     imagecarmerauri = uri.fromfile(carmerafile);      intent.putextra(android.provider.mediastore.extra_output,             imagecarmerauri);      try {         intent.putextra("return-data", true);         startactivityforresult(intent, action_take_carmera);     } catch (activitynotfoundexception e) {         // nothing     } } 

and pls check save file length, if length equal 0,you should delete it(some people open camera don't take photo,there have empty file,delete it)

    @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     // todo auto-generated method stub     super.onactivityresult(requestcode, resultcode, data);     if (requestcode == action_take_carmera)      {      } } 

you can after photo taken in function.

there have other ways this


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -