android - Open internal storage image with Intent.ACTION_EDIT exception with FileProvider android
问题描述
In my application there is a need where i have to EDIT an internal storage image and save the new to internal storage again. So i have tried to make an Intent.ACTION_EDIT in order to use the default Gallery app for editing the image.
if (it.fileName.fileType() == IMAGE_TYPE) {
createEditImageFile()
val intent = Intent(Intent.ACTION_EDIT).apply {
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
putExtra(MediaStore.EXTRA_OUTPUT,
FileProvider.getUriForFile(this@MyActivity,BuildConfig.APPLICATION_ID,
File(currentEditPhotoPath)))
setDataAndType(uri, "image/*")
}
startActivity(intent)
return
}
So i get hte following exception which is reasonable since i dont have my FileProvider exported in the Manifest.
java.lang.SecurityException: Permission Denial: writing androidx.core.content.FileProvider uri content://{package_name}/external_path_files/Pictures/JPEG_20200720_163239_edit_5491322030710880687.jpg from pid=26681, uid=10206 requires the provider be exported, or grantUriPermission()
So when i change my in the Manifest.xml file to
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}"
android:exported="true"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
android:exported="false"
tools:node="remove" />
and the paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path
name="files"
path="." />
<external-files-path
name="external_path_files"
path="." />
<external-path
name="external_files"
path="."/>
</paths>
CreateEditImageFile() if the following
@Throws(IOException::class)
private fun createEditImageFile(): File {
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())
val storageDir: File? = getExternalFilesDir(Environment.DIRECTORY_PICTURES)
return File.createTempFile("JPEG_${timeStamp}_edit_", ".jpg", storageDir).apply {
currentEditPhotoPath = absolutePath
}
}
i have the following fail on the Build.
Manifest merger failed : Attribute provider#androidx.core.content.FileProvider@exported value=(false) from AndroidManifest.xml:158:13-37
is also present at AndroidManifest.xml:167:13-36 value=(true).
Suggestion: add 'tools:replace="android:exported"' to <provider> element at AndroidManifest.xml:155:9-163:20 to override.
I dont really understand the error, and the most weird is that the AndroidManifest.xml lines are not where the provider is defined. How can i solve this? Thank you
解决方案
推荐阅读
- django - 无法符号化堆栈跟踪:网络请求失败 - React Native
- javascript - Facebook sparkar 中的 DeepLink 通信如何工作?
- linear-regression - 线性规划与迭代重新加权最小二乘运行时间
- javascript - “beforeunload”事件未在 Google Chrome 上触发弹出窗口
- python - 使用列值之一为现有数据框创建“市值”列
- netsuite - 如何在我的 NetSuite 环境中设置 suiteapp 报告 360
- sorting - 对堆积面积图 Power Bi 中的图例进行排序
- python - AttributeError:“collections.OrderedDict”对象没有属性“split”
- visual-studio-code - 我在哪里可以找到 VS Code 的 editor.tokenColorCustomization 设置中的所有可用字段?
- sql - 连接Oracle sql中的两个列值