• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android FileProvider

Hello glorious android community! Need some help here. I've been trying this for some time and i just can't get it done. It sounds simple but ive been trying and leveraging from examples out there and i fail all the time. My objective is to create a share button to send an audio file from my android raw folder to whatsapp.. simple.. i tried share intent and it doesnt work. I know we can use FileProvider but I am struggling at it.. can someone advise or point me to a useful walkthrough?
 
I've had a look at the documentation for FileProvider, and it does provide a way to share data between apps. Maybe you could show your current code, and explain more about what's going wrong and what doesn't work?

Here's an extract from the Google docs on the subject

https://developer.android.com/reference/android/support/v4/content/FileProvider.html


Serving a Content URI to Another App

There are a variety of ways to serve the content URI for a file to a client app. One common way is for the client app to start your app by callingstartActivityResult(), which sends an Intent to your app to start an Activity in your app. In response, your app can immediately return a content URI to the client app or present a user interface that allows the user to pick a file. In the latter case, once the user picks the file your app can return its content URI. In both cases, your app returns the content URI in an Intent sent via setResult().

You can also put the content URI in a ClipData object and then add the object to an Intent you send to a client app. To do this, callIntent.setClipData(). When you use this approach, you can add multiple ClipData objects to the Intent, each with its own content URI. When you call Intent.setFlags() on the Intent to set temporary access permissions, the same permissions are applied to all of the content URIs.

Note: The Intent.setClipData() method is only available in platform version 16 (Android 4.1) and later. If you want to maintain compatibility with previous versions, you should send one content URI at a time in the Intent. Set the action to ACTION_SEND and put the URI in data by callingsetData().

More Information
To learn more about FileProvider, see the Android training class Sharing Files Securely with URIs.
 
Back
Top Bottom