Skip to content

CacheFileProvider#

Open in GitHub

Latest Release Last Update License

Stars Forks

This is a minimal library with a few lines of code and without dependencies that offers a simple file provider (simple read only access for sharing files with other apps).

Features#

  • offers functions to copy a file to the underlying FileProvider folder
  • allows to simply share a file without any setup from user side
  • minimal size - contains only 8 functions inside 2 classes

🔗 Dependencies#

This library does not have any dependencies!

Setup Gradle#

This library is distributed via JitPack.io.

1/2: Add jitpack to your project's build.gradle
repositories {
    maven { url "https://jitpack.io" }
}
2/2: Add dependencies to your module's build.gradle
// use the latest version of the library
val cachefileprovider = "<LATEST-VERSION>" 

// add library dependency
implementation("com.github.MFlisar:CacheFileProvider:$cachefileprovider")

⌨ Usage#

It works as simple as following:

// create a file that can be shared with external apps
val cacheFile = CachedFileProvider.copyFileToCache(context, file)
val cacheFile = CachedFileProvider.copyFileToCache(context, uri)

// get the shareable uri for this file
val uri = CachedFileProvider.getCacheFileUri(context, cacheFile.name)

// now you can share the uri with external apps
// ATTENTION: if you share the file via an intent,
// also use Intent.FLAG_GRANT_READ_URI_PERMISSION
// ...

💡 Tipp

If you want to share the cached file with an email app, then check out FeedbackManager - its an utility based on CacheFileProvider that does exactly that. It also takes care of the above mentioned Intent.FLAG_GRANT_READ_URI_PERMISSION.