Android.os.FileUriExposeException: файл:///storage/emulated/0/Download/FileNmae доступен за пределами приложения через IAndroid

Форум для тех, кто программирует под Android
Anonymous
Android.os.FileUriExposeException: файл:///storage/emulated/0/Download/FileNmae доступен за пределами приложения через I

Сообщение Anonymous »

У меня есть функция открытия файла после завершения загрузки:

Код: Выделить всё

fun openDownloadedFile(context: Context?, fileName: String) {
val storageDirectory =
Environment.getExternalStorageDirectory().toString() + STORAGE_DIRECTORY + "/${fileName}"
val file = File(storageDirectory)

if (file.exists()) {
val downloadedFileUri = Uri.fromFile(file)
val fileIntent = Intent(Intent.ACTION_VIEW)
fileIntent.setDataAndType(downloadedFileUri, "application/vnd.android.package-archive")
fileIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK

context?.startActivity(fileIntent)
}
}
Я также объявил поставщика файлов в файле Manifest.xml

Код: Выделить всё

    android:name="androidx.core.content.FileProvider"
android:authorities="net.mytvplus.stbstore.file_provider"
android:exported="false"
android:grantUriPermissions="true">


file_provider.xml: После завершения загрузки приложение аварийно завершает работу, и в logcat появляется следующее сообщение:

android.os. FileUriExposeException:
file:///storage/emulated/0/Download/FileNmae доступен за пределами приложения
через Intent.getData()

Любая помощь?

Подробнее здесь: https://stackoverflow.com/questions/764 ... d-filenmae

Вернуться в «Android»