Я пытаюсь открыть файл в своем приложении на платформе Android.Я использую:
let intent = new android.content.Intent(android.content.Intent.ACTION_VIEW);
let fileURI = android.net.Uri.fromFile(new java.io.File(file.path));
intent.setDataAndType(fileURI, "application/pdf");
let activity = android.content.Intent.createChooser(intent, `Open Document with :`);
app.android.currentContext.startActivity(activity);
И это работает для Android версии 7.1.1 и версий до.Но на версии 8.0.У меня такая ошибка:
android.os.FileUriExposedException: file:///data/user/0/... exposed beyond app through Intent.getData()
Итак, я пытаюсь исправить проблему с android.support.v4.content.FileProvider.
Я изменил свой код на:
let intent = new android.content.Intent(android.content.Intent.ACTION_VIEW);
intent.addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION);
let context = application.android.currentContext;
let nativeFile = new java.io.File(file.path);
var uri = new android.support.v4.content.FileProvider.getUriForFile(context,"${applicationId}.provider,nativeFile",nativeFile);
intent.setDataAndType(uri, "application/pdf");
application.android.currentContext.startActivity(android.content.Intent.createChooser(intent, "Open File...");
И я модифицирую AndroidManifest.xml, добавив следующее:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
Я создал файл с именем provider_paths.xml в папке App_Ressources / Android / xml:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
Я удаляю и добавляю платформу.но я не могу запустить код, потому что у меня все еще есть ошибка:
Property 'FileProvider' does not exist on type 'typeof content'
нажмите здесь, чтобы увидеть захват