Captured Picture Not Showing up in imageView in Dialog - Android Studio -
im trying access picture taken camera in dialog fragment. code. there no errors, image isn't loading imageview in dialog
mainactivity
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data);
taskadapter adapter = new taskadapter(this); view view = layoutinflater.from(this).inflate(r.layout.picture_setup_dialog, null); button mtaskbutton = (button)view.findviewbyid(r.id.taskbutton); button mexambutton = (button)view.findviewbyid(r.id.exambutton); imageview muserpicture = (imageview) view.findviewbyid(r.id.userpicture); if (resultcode == result_ok){ if (requestcode == adapter.request_take_photo){ //write code happens after picture taken here picasso.with(this).load(adapter.getimageuri()).into(muserpicture); alertdialog.builder builder = new alertdialog.builder(this) .settitle("add picture") .setview(view) .setpositivebutton("add", null) .setnegativebutton("cancel", null); alertdialog dialog = builder.create(); dialog.show(); } }
} taskadapter
mtakepicbutton.setonclicklistener(new view.onclicklistener() {
@override public void onclick(view v) { mmediauri = getoutputmediafileuri(media_type_image); if (mmediauri == null){ toast.maketext(mcontext, "there problem accessing device's external storage", toast.length_long).show(); } else{ intent takephotointent = new intent(mediastore.action_image_capture); ((activity) mcontext).startactivityforresult(takephotointent, request_take_photo); takephotointent.putextra(mediastore.extra_output, mmediauri); } } private uri getoutputmediafileuri(int mediatype) { //check external storage if (isexternalstorageavailable()){ //get uri //1.get external storage directory file mediastoragedir = mcontext.getexternalfilesdir(environment.directory_pictures); //2.create unique file name string filename = ""; string filetype = ""; string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date()); if (mediatype == media_type_image) { filename = "img_"+ timestamp; filetype = ".jpg"; } else { return null; } //3.create file file mediafile; try { mediafile = file.createtempfile(filename, filetype, mediastoragedir); //4.return file's uri mimageuri = uri.fromfile(mediafile); return mimageuri; } catch (ioexception e){ toast.maketext(mcontext, "error creating file", toast.length_long).show(); } } //something went wrong return null; } private boolean isexternalstorageavailable(){ string state = environment.getexternalstoragestate(); if (environment.media_mounted.equals(state)) return true; else return false; } });
public uri getimageuri(){ return mimageuri; }
Comments
Post a Comment