2016-02-23 74 views
1

目前我正在開發一個項目,我必須訪問可以在Root中找到的Music目錄。我試圖讓與的PhoneGap /科爾多瓦插件目錄:https://github.com/apache/cordova-plugin-file無法訪問根目錄phonegap

我試了很多東西,我做研究的谷歌,但找不到什麼好.. 這裏是我的代碼:

/* THIS IS PLACED IN THE onDeviceReady FUNCTION! */   
window.requestFileSystem(window.TEMPORARY, 1024*1024, onFileSystemSuccess, function(e) { alert("Something went wrong.."); }); 
alert("5"); 
/*************************************************/ 

    function onFileSystemSuccess(fileSystem) { 
     alert("6"); // just for testing 
     fileSystem.root.getDirectory("Music", {}, getDirSuccess, function(e) { alert("Doesn't work"); }); 
    } 

    function getDirSuccess(dirEntry) { 
     alert("7"); 
     var directoryReader = dirEntry.createReader(); 
     directoryReader.readEntries(readerSuccess,fail); 
    } 
+0

你能給我截圖你想打開的文件位置嗎? – Microsmsm

+0

@Microsmsm http://prntscr.com/a790i5 – 247errorsnl

回答

1

嗯......你可能想嘗試window.resolveLocalFilesystemURL()而不是window.requestFilesystem()如果你正在尋找讀取文件系統。

我有一個示例例程,它遍歷這裏的一堆目錄:How to get documents in an android directory that PhoneGap will see。這可能有助於縮小搜索範圍。

+0

我會看看這個,謝謝。 – 247errorsnl

+0

我通過使用windows.resolveLocalFileSystemURL()而不是window.requestFilesystem()修復了它。 – 247errorsnl

0

嘗試以下路徑:

/android_asset/www/song.mp3 
+0

我想訪問Android的音樂目錄,而不是我的WWW文件夾 – 247errorsnl