Android - onActivityResult from DialogFragment -
i have webview app , want upload image files camera of gallery web page.
i implemented camera upload i'm trying implement dialogfragment let user choose upload file.
the code in fragment , can't pass camera results onactivityresult function, dialogfragment class`public static class editnamedialog extends dialogfragment {
private button buttoncamera; public file createimagefile() throws ioexception { // create image file name string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date()); string imagefilename = "jpeg_" + timestamp + "_"; file storagedir = getactivity().getexternalfilesdir(environment.directory_pictures); file image = file.createtempfile( imagefilename, /* prefix */ ".jpg", /* suffix */ storagedir /* directory */ ); // save file: path use action_view intents mcurrentphotopath = "file:" + image.getabsolutepath(); return image; } public void dispatchtakepictureintent() { intent takepictureintent = new intent(mediastore.action_image_capture); // ensure there's camera activity handle intent if (takepictureintent.resolveactivity(getactivity().getpackagemanager()) != null) { // create file photo should go file photofile = null; try { photofile = createimagefile(); } catch (ioexception ex) { // error occurred while creating file } // continue if file created if (photofile != null) { uri photouri = fileprovider.geturiforfile(getactivity(), "com.mysite.fileprovider", photofile); takepictureintent.putextra(mediastore.extra_output, photouri); finalphotouri = photouri; getactivity().startactivityforresult(takepictureintent, request_take_photo); } } } public editnamedialog() { // empty constructor required dialogfragment } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_photo, container); return view; } @override public void onviewcreated(view view, @nullable bundle savedinstancestate) { super.onviewcreated(view, savedinstancestate); // field view buttoncamera = (button) view.findviewbyid(r.id.buttoncamera); buttoncamera.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { dispatchtakepictureintent(); } }); } }`
and onactivityresult class:
@override public void onactivityresult(int requestcode, int resultcode, intent intent) { super.onactivityresult(requestcode, resultcode, intent); if(requestcode==request_file_picker) { if(mfilepathcallback5!=null) { if (finalphotouri != null) { mfilepathcallback5.onreceivevalue(new uri[]{ finalphotouri }); } } mfilepathcallback5 = null; } }
how can pass finalphotouri onactivityresult function?
change dialogfragment appcompatactivity , change it's theme manifest dialog , call startactivityforresult() , result function
Comments
Post a Comment