Skip to content

Instantly share code, notes, and snippets.

@mg6maciej
Created May 11, 2017 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mg6maciej/598b09193ee4bcfa5ba1fd355692dc3a to your computer and use it in GitHub Desktop.
Save mg6maciej/598b09193ee4bcfa5ba1fd355692dc3a to your computer and use it in GitHub Desktop.
Real hacky way to let yourself use android.support.v4.content.FileProvider with exported and without grantUriPermissions.
import android.content.Context
import android.content.pm.ProviderInfo
import android.support.v4.content.FileProvider
class FileProviderHack : FileProvider() {
override fun attachInfo(context: Context, info: ProviderInfo) {
try {
super.attachInfo(context, info)
} catch (ex: SecurityException) {
// ignore
}
val method = FileProvider::class.java.getDeclaredMethod("getPathStrategy", Context::class.java, String::class.java)
method.isAccessible = true
val field = FileProvider::class.java.getDeclaredField("mStrategy")
field.isAccessible = true
val result = method.invoke(null, context, info.authority)
field.set(this, result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment