Created
May 11, 2017 15:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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