所以我使用React原生WebView来显示本地html文件。我的文件位于/storage/emulated/0/Android/data/com.package/files/sample.html
。我已经使用React Native fs在这个位置编写了文件。
现在我有一个网络视图声明为:
<WebView source={{uri : 'file:///storage/emulated/0/Android/data/com.package/files/sample.html'}}/>
因此,每当我运行此程序时,WebView都会显示一个页面,上面写着net::ERR_ACCESS_DENIED
。如果我使用React Native fs readfile从该路径读取文件,我可以做到。为什么我无法访问webView中的文件路径?
最终修复了它。allowFileAccess
是WebView的道具,默认设置为false。将其设置为true允许它从的任何位置访问.html文件
这就是文档所说的Boolean that sets whether the WebView has access to the file system. The default value is false.