Open Dreamxhx opened 3 years ago
并不是因为微信或者QQ目录,而是因为文件是应用分身创建的原因。我也正在找解决方案
@Dreamxhx 在fileprivider中添加
<root-path
name="root-path"
path="" />
创建自己的工具方法
fun file2Uri(file: File?): Uri? {
if (!FileUtils.isFileExists(file)) return null
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val authority = Utils.getApp().packageName + ".fileprovider"
FileProvider.getUriForFile(
Utils.getApp(), authority,
file!!
)
} else {
Uri.fromFile(file)
}
}
在调用UriUtils.file2Uri(file)时候报的一个错误。线上统计的都是微信或者QQ目录下的错误
Thread Name: 'main' Back traces starts. java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/999/Pictures/WeiXin/mmexport1632153804305.jpg at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:744) at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:418) at com.blankj.utilcode.util.UriUtils.file2Uri(UriUtils.java:61)