i opening activity whatsapp or camera fragment when going current activity goes root fragment instead of recent fragment. need use fragment activity recent fragment or other solution there ? have searched lot till did not appropriate solution.
private void galleryintent() { intent intent = new intent(); intent.settype("image/*"); intent.setaction(intent.action_get_content);// getactivity().startactivityforresult(intent.createchooser(intent, "select file"),select_file); } private void cameraintent() { intent intent = new intent(mediastore.action_image_capture); getactivity().startactivityforresult(intent, request_camera); } @override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if (resultcode == activity.result_ok) { if (requestcode == select_file) onselectfromgalleryresult(data); else if (requestcode == request_camera) oncaptureimageresult(data); } } private void oncaptureimageresult(intent data) { bitmap thumbnail = (bitmap) data.getextras().get("data"); bytearrayoutputstream bytes = new bytearrayoutputstream(); thumbnail.compress(bitmap.compressformat.jpeg, 90, bytes); bytearray = bytes.tobytearray(); // file destination = new file(environment.getexternalstoragedirectory(), "dir/savings.csv"); // if (!destination.exists()) { // destination.mkdirs(); // destination.createnewfile(); // } // // file destination = new file(environment.getexternalstoragedirectory()+file.separator+"wish-a-mitr"+file.separator, // system.currenttimemillis() + ".jpg"); file path = environment.getexternalstoragepublicdirectory( environment.directory_pictures); file destination = new file(path, system.currenttimemillis() +".jpg"); fileoutputstream fo; try { if(path.exists()) { path.mkdirs(); destination.createnewfile(); } fo = new fileoutputstream(destination); fo.write(bytes.tobytearray()); fo.close(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } roundedimageview.setimagebitmap(thumbnail); // call method uri bitmap uri tempuri = getimageuri(getcontext(), thumbnail); // call method actual path finalfile = new file(getrealpathfromuri(tempuri)); } @suppresswarnings("deprecation") private void onselectfromgalleryresult(intent data) { bitmap bm=null; if (data != null) { try { bm = mediastore.images.media.getbitmap(getactivity().getcontentresolver(), data.getdata()); bytearrayoutputstream bytes = new bytearrayoutputstream(); bm.compress(bitmap.compressformat.jpeg, 90, bytes); bytearray = bytes.tobytearray(); } catch (ioexception e) { e.printstacktrace(); } } roundedimageview.setimagebitmap(bm); // call method uri bitmap uri tempuri = getimageuri(getcontext(), bm); // call method actual path finalfile = new file(getrealpathfromuri(tempuri)); } public uri getimageuri(context incontext, bitmap inimage) { bytearrayoutputstream bytes = new bytearrayoutputstream(); inimage.compress(bitmap.compressformat.jpeg, 100, bytes); string path = mediastore.images.media.insertimage(incontext.getcontentresolver(), inimage, "imagefile", null); return uri.parse(path); } public string getrealpathfromuri(uri uri) { cursor cursor = getcontext().getcontentresolver().query(uri, null, null, null, null); cursor.movetofirst(); int idx = cursor.getcolumnindex(mediastore.images.imagecolumns.data); return cursor.getstring(idx); }
Comments
Post a Comment