java - Android - how can i onCreate launch the camera without crashing the apps? -
i have problem, first activity window launching second activity window need directly see cam preview > take snap shot > show preview on activity window.
now, way need launch (expected , correct way of user demand), after taking picture , coming window apps crash on way.
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); this.imageview = (imageview)this.findviewbyid(r.id.picture); button photobutton = (button) this.findviewbyid(r.id.capture_btn); //photobutton.setonclicklistener(new view.onclicklistener() { //@override //public void onclick(view v) { intent cameraintent = new intent(android.provider.mediastore.action_image_capture); startactivityforresult(cameraintent, camera_request); // } //}); }
but way not crash, in way wrong use case, cause becomes 2 button press apps.
public class mainactivity extends activity implements onclicklistener { private static final int camera_request = 1888; private static final int pic_crop = 0; private imageview imageview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); this.imageview = (imageview)this.findviewbyid(r.id.picture); button photobutton = (button) this.findviewbyid(r.id.capture_btn); photobutton.setonclicklistener(new view.onclicklistener() { //@override public void onclick(view v) { intent cameraintent = new intent(android.provider.mediastore.action_image_capture); startactivityforresult(cameraintent, camera_request); } }); } protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == camera_request && resultcode == result_ok) { bitmap photo = (bitmap) data.getextras().get("data"); imageview.setimagebitmap(photo); } } @override public void onclick(view arg0) { // todo auto-generated method stub } }
Comments
Post a Comment