我需要訪問面向 Android 的 Cordova 應用程式中的檔案。我需要能夠通過傳遞 URI(例如“file://...”或“https://...”)來完成它,因為這是我需要傳遞將打開檔案的 API 的格式(Howler.js播放 .mp3 檔案)。
這似乎排除了cordova-plugin-file,據我所知。我已經嘗試在本地和遠程托管。我試過安裝cordova-plugin-whitelist。我的 config.xml 包含
<access origin="*"/> <allow-navigation href="*"/>我的 html 包含<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data:"/>.
因此,我涵蓋了任何檔案中提到的盡可能多的基礎,但并不高興 - 訪問檔案的權限總是被拒絕。非常感謝建議。
編輯 - - - - - - - - - -
為了回應下面的埃里克,我嘗試編輯我的 config.xml,現在如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>HelloCordova</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="[email protected]" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html"/>
<access origin="*"/>
<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="tel:*"/>
<allow-intent href="sms:*"/>
<allow-intent href="mailto:*"/>
<allow-intent href="geo:*"/>
<platform name="android">
<allow-intent href="market:*"/>
<access origin="*"/>
<preference name="AndroidInsecureFileModeEnabled" value="true" />
</platform>
<platform name="ios">
<allow-intent href="itms:*"/>
<allow-intent href="itms-apps:*"/>
</platform>
<!-- <hook src="node_modules/cordova-import-npm/scripts/importNpmPackages.js" type="before_prepare"/> -->
</widget>
但是我的構建現在崩潰了,這里有一條錯誤訊息可見
uj5u.com熱心網友回復:
您可以嘗試添加
<preference name="AndroidInsecureFileModeEnabled" value="true" />
到您的 config.xml,很可能是 CORS 問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/358656.html
標籤:javascript 安卓 科尔多瓦 科斯 本地文件
