android - How can i send either an image or a video file using ACTION_SEND? -
i want share either image or video file using action_send
. when users taps on image , selects "share image/video" should send either image selected or video selected.
here code using:
if (filep != null) { } file sending=new file(filep); intent intent = new intent(); intent.setaction(android.content.intent.action_send); intent.setdataandtype(uri.fromfile(sending),getmimetype(sending.getabsolutepath())); intent.putextra(intent.extra_stream, sending); startactivity(intent.createchooser(intent , "share")); } private string getmimetype(string url) { string parts[]=url.split("\\."); string extension=parts[parts.length-1]; string type = null; if (extension != null) { mimetypemap mime = mimetypemap.getsingleton(); type = mime.getmimetypefromextension(extension); } return type;
so when testing, takes me app want use share i.e whatsapp, facebook, email etc. , when selecting either one, says "sharing failed, please try again." can't seem figure out why doesn't work. have same code display either image or video file full screen action_view
, seems work great not sharing.
can assist please?
extra_stream
needs uri
, , not passing uri
. use uri.fromfile()
construct uri
.
also, replace setdataandtype()
settype()
, action_send
not use data aspect of intent
.
Comments
Post a Comment