Delphi 10.3.1 Secure File Sharing解决应用间文件共享

Delphi 10.3.1 为Android项目提供了Secure File Sharing选择项,默认是False。这一项是设置什么呢?
原来,Android 7及以后的版本,为了加强OS的安全性,不允许一个app访问其他app的文件,如果访问,则会出现这样的错误:
java.lang.nullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageInfo.LoadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object referance

为了解决这个问题,将Secure File Sharing设置为True。设置后,ide会为我们在AndroidManifest.template.xml增加如下内容:
复制代码
复制代码
android:name="android.support.v4.content.FileProvider" android:authorities="com.embarcadero.CCSuperPlayer.fileprovider" android:exported="false" android:grantUriPermissions="true"> android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> 复制代码 复制代码 同时生成文件provider_paths.xml,内容如下: 关于上面生成的内容如何理解,可以参考: 1.Android 7.0适配-应用之间共享文件(FileProvider) 2.Android7.0行为变更之适配File Provider的方法 最后总结下,如果你的代码中用到File://,则需要按上面的方法解决。 后记:如果你的项目是用旧版delphi建的,如10.2,那么,需要在10.3.1下重建这个项目,才能确保Secure File Sharing选择项生效,生成正确的配置文件,不然,不会生成配置文件,有朋友遇到过。 来源:https://www.cnblogs.com/dqi1999/articles/14236469.html
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.046766996383667 seconds