I'm looking for a way to share files between apps running in the following scenario:
- In our app, there is a list of files. The user clicks the Share button, and we show him the selection dialog that displays list of apps that can take the file. For example, user can choose Gmail, to create the letter and attach to this letter selected file or user can transfer the file via Bluetooth.
- The file can be in a private directory of the our app.
- The file can be anywhere in the file system excepting for the dirs that requires root access.
- App that receives the file may not have
READ_EXTERNAL_STORAGE
permission. - It should work from API level 14 and up to the newest versions.
As I understand, the only way to fulfill all conditions is the implementing in my app custom ContentProvider
or FileProvider
. That ContentProvider
will give the content URI for the file, and we attach that URI to the ACTION_SHARE
Intent with the FLAG_GRANT_READ_URI_PERMISSION
.
I worried that I have missed some other simple and clean solution. Whether is some other reliable alternative to ContentProvider exists at all, and if it exists, than what is it?