Android Camera Issue -


hi helper new android programming ,i developing simple app in 1 image button 1 imageview,and 2 normal buttons name save , confirm

working: per idea app launched 1 image button when user click on button camera intent opened user click image finished activity gets starting intent 1 more control imageview in pic capture displayed plus button named save user clicks on save button save button gets invisible , confirm button gets visible when user click on confirm image in imageview must saved in sd card .

bug: when user clicks on confirm display toast "something went wrong",i tried explore emulator pic capture not available ,even no error in log-cat ,nor app gets crash

please tell me wrong in code

    public class mainactivity extends activity implements onclicklistener { imagebutton ib; button bconfirm, bsave; imageview iv; intent i; final static int cameradata = 0; bitmap bmp; file path = null; file file = null; string folder = "/sdcard/propertypic";   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);     initalize();     inputstream = getresources().openrawresource(r.drawable.ic_launcher);     bmp = bitmapfactory.decodestream(is);  } 

code initializing variables

private void initalize() {     // todo auto-generated method stub     ib = (imagebutton) findviewbyid(r.id.ibtakepic);     bconfirm = (button) findviewbyid(r.id.bconfirm);     bsave = (button) findviewbyid(r.id.bsave);     iv = (imageview) findviewbyid(r.id.imageview1);     ib.setonclicklistener(this);     bconfirm.setonclicklistener(this);     bsave.setonclicklistener(this);  } 

onclick method button pressed

           @override        public void onclick(view v) {     // todo auto-generated method stub     switch (v.getid()) {     case r.id.ibtakepic:         = new intent(android.provider.mediastore.action_image_capture);         startactivityforresult(i, cameradata);          break;     case r.id.bconfirm:         bsave.setvisibility(view.visible);         bconfirm.setvisibility(view.gone);          break;     case r.id.bsave:         save();          break;     } }                 private void save() {     // todo auto-generated method stub      final file mydir = new file(folder);     mydir.mkdirs();     final random generator = new random();     int n = 10000;     n = generator.nextint(n);     final string fname = "property:" + n + ".png";     file = new file(mydir, fname);     if (file.exists())         file.delete();     try {         final fileoutputstream out = new fileoutputstream(file);         bmp.compress(bitmap.compressformat.png, 100, out);         out.flush();         out.close();         sendbroadcast(new intent(intent.action_media_mounted,                 uri.parse("file://" +                       environment.getexternalstoragedirectory())));         toast.maketext(getapplication(), "image saved", toast.length_short)                 .show();           } catch (exception e) {           toast.maketext(getapplication(),                 "something went wrong check if have enough memory",                 toast.length_long).show();      }  }          @override      protected void onactivityresult(int requestcode, int resultcode, intent            data)           {     // todo auto-generated method stub     super.onactivityresult(requestcode, resultcode, data);     if (resultcode == result_ok) {         toast t = toast.maketext(mainactivity.this, "image captured",                 toast.length_short);         t.show();         iv.setvisibility(view.visible);         bundle extras = data.getextras();         bmp = (bitmap) extras.get("data");         iv.setimagebitmap(bmp);         bconfirm.setvisibility(view.visible);}}} 

it gratefull may me


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -