java - Sharing the audio file located on an url with other apps in android -


my android application has mp3 files sitting on amazon s3 bucket. have url access audio clip. able play audio clip using mediaplayer passing url data source of media player.

i creating application lets user share audio clips app other im apps whatsapp. so, provide share widget on activity , upon cliking on widget whatsapp should opened , user should able select contact wants share audio clip.

for need download audio clip local storage system , share file other app using contenturi. unable figure out best way it.

as per android documentation below code canbe used send binary files:

intent shareintent = new intent(); shareintent.setaction(intent.action_send); shareintent.putextra(intent.extra_stream, uritoimage); shareintent.settype("image/jpeg"); startactivity(intent.createchooser(shareintent, getresources().gettext(r.string.send_to))); 

i assuming audio files binary files. so, using below code send audio clip.

intent intent = new intent(android.content.intent.action_send); intent.putextra(intent.extra_stream, uritoimage); intent.settype("audio/mpeg3"); startactivity(intent); 

looks piece missing here "uritoimage". can me understand how "uritoimage" resource located @ url. ?

updated code per commonsware's comment. below updated code:

intent intent = new intent(android.content.intent.action_send);                 uri contenturi = uri.fromfile(new file(clipaudiourl));                 intent.putextra(intent.extra_stream, contenturi);                 intent.settype("audio/mpeg");                 intent.setpackage("com.whatsapp");                 startactivity(intent); 

upon touching share widget watsapp being opened directly(which want), share familing error "share failed". assuming because of uri have used below code:

uri contenturi = uri.fromfile(new file(clipaudiourl)); 

as per commonsware's comment, whatsapp expect uri either in format "file:\" or "content:\"

could please me convert url in format of either "file:\" or "content:\". thank you.

i provide share widget on activity , upon cliking on widget whatsapp should opened

only if user chooses whatsapp. please not assume users of app have whatsapp installed or want use whatsapp in app.

for need download audio clip local storage system , share file other app using contenturi.

technically, use s3 url action_send, though implies url public.

otherwise, download file using whatever want (aws sdk, httpurlconnection, okhttp, etc.) internal storage (e.g., getcachedir()), use fileprovider serve other apps. fileprovider can give uri use action_send.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -