android - How can I share an image that I have taken in my app? -
i have app in i'm taking photos , i'm trying share them directly through app. problem i'm having when chooser comes , pick one, error toast pops , says "unable attach file". takes me app , else still works. i'm assuming means have save image first, i'm not sure if i'm doing correctly. found examples online of how save images i'm not sure if that's problem or if share intent problem.
final button sharebutton = (button) findviewbyid(r.id.sharebutton); sharebutton.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { imageview.setdrawingcacheenabled(true); bitmap b = imageview.getdrawingcache(); mediastore.images.media.insertimage(getcontentresolver(), b, "title", "description"); intent shareintent = new intent(intent.action_send); shareintent.settype("image/jpeg"); bitmapdrawable bitmapdrawable = (bitmapdrawable) imageview.getdrawable(); bitmap image = bitmapdrawable.getbitmap(); bytearrayoutputstream bytes = new bytearrayoutputstream(); image.compress(bitmap.compressformat.jpeg, 100, bytes); file f = new file(environment.getexternalstoragedirectory() + file.separator + "temp.jpg"); try { f.createnewfile(); fileoutputstream fo = new fileoutputstream(f); fo.write(bytes.tobytearray()); } catch (ioexception e) { e.printstacktrace(); } shareintent.putextra(intent.extra_stream, uri.parse(environment.getexternalstoragedirectory().getpath())); startactivity(intent.createchooser(shareintent, "share image")); } }); i have "title" , "description" in placeholders until can work.
try replace :
shareintent.putextra(intent.extra_stream, uri.parse(environment.getexternalstoragedirectory().getpath())); with :
shareintent.putextra(intent.extra_stream, uri.fromfile(f));
Comments
Post a Comment