我在使用cordova.file
插件從文件系統讀取文件時遇到問題。我使用下面的示例代碼:無法獲取cordova.file插件在混合應用程序中工作
function onInitFs(fileSystem) {
console.log("filesystem loaded!");
fileSystem.root.getFile(filePath, {}, function (fileEntry) {
console.log("DirectoryEntry.getFile succeeded!");
fileEntry.file(function (file) {
console.log("FileEntry.file succeeded!");
var reader = new FileReader();
reader.onloadend = function (e) {
//file contents are in this.result
};
reader.readAsText(file);
}, console.log);
}, console.log);
}
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onInitFs, console.log);
,這裏是我在輸出窗口中看到錯誤消息:
D/PluginManager(2597): init()
E/cutils ( 915): Failed to mkdirat(/storage/sdcard/Android): Read-only file system
W/ContextImpl(2597): Failed to ensure directory: /storage/sdcard/Android/data/io.cordova.<myappname>/files
W/System.err(2597): java.lang.NullPointerException
W/System.err(2597): at org.apache.cordova.file.FileUtils.getAvailableFileSystems(FileUtils.java:132)
W/System.err(2597): at org.apache.cordova.file.FileUtils.initialize(FileUtils.java:192)
W/System.err(2597): at org.apache.cordova.PluginEntry.createPlugin(PluginEntry.java:96)
W/System.err(2597): at org.apache.cordova.PluginManager.startupPlugins(PluginManager.java:195)
W/System.err(2597): at org.apache.cordova.PluginManager.init(PluginManager.java:106)
W/System.err(2597): at org.apache.cordova.CordovaWebView.loadUrlIntoView(CordovaWebView.java:457)
W/System.err(2597): at org.apache.cordova.CordovaWebView.loadUrlIntoView(CordovaWebView.java:444)
W/System.err(2597): at org.apache.cordova.CordovaWebView.loadUrlIntoView(CordovaWebView.java:541)
W/System.err(2597): at org.apache.cordova.CordovaWebView.loadUrl(CordovaWebView.java:435)
W/System.err(2597): at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:391)
W/System.err(2597): at io.cordova.<myappname>.onCreate(ApprovalsHybrid.java:33)
W/System.err(2597): at android.app.Activity.performCreate(Activity.java:5231)
W/System.err(2597): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
W/System.err(2597): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
W/System.err(2597): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
W/System.err(2597): at android.app.ActivityThread.access$800(ActivityThread.java:135)
W/System.err(2597): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
W/System.err(2597): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(2597): at android.os.Looper.loop(Looper.java:136)
W/System.err(2597): at android.app.ActivityThread.main(ActivityThread.java:5017)
W/System.err(2597): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(2597): at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err(2597): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
W/System.err(2597): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
W/System.err(2597): at dalvik.system.NativeStart.main(Native Method)
I/System.out(2597): Error adding plugin org.apache.cordova.file.FileUtils.
W/Vold ( 915): Returning OperationFailed - no handler for errno 30
我使用的是多設備混合應用程序插件VS和Android模擬器。
UPDATE1:我3210:
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:vs="http://schemas.microsoft.com/appx/2014/htmlapps" id="io.cordova.<myappname>" version="1.0.0.0" xmlns="http://www.w3.org/ns/widgets">
<name><myappname></name>
<description>
A blank project that uses Apache Cordova to help you build an app that targets multiple mobile platforms: Android, iOS, Windows, and Windows Phone.
</description>
<author href="http://cordova.io" email="[email protected]">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<preference name="SplashScreen" value="screen" />
<vs:features>
<vs:feature>[email protected]</vs:feature>
<vs:feature>[email protected]</vs:feature>
</vs:features>
<vs:platformSpecificValues />
</widget>
UPDATE2:好吧,我想通了,也有一些問題cordova.file
插件V1.2.0。當我將cordova.file
插件版本從v1.2.0切換到v1.1.0時,我開始調用requestFileSystem
的成功回調。但getFile
因FileNotFoundException
而失敗。原因可能是不正確的相對路徑。
UPDATE3:固定readAsText
什麼在您的配置? – 2014-10-10 10:39:39
我已將config.xml內容添加到問題 – 2014-10-10 15:43:24