【问题标题】:Is it possible to read content from own Android file system root directory with cordova/phonegap?是否可以使用 cordova/phonegap 从自己的 Android 文件系统根目录中读取内容?
【发布时间】:2016-09-19 13:16:14
【问题描述】:

我想知道是否可以像AndroidFile Manager那样从根目录读取文件?我想创建一个音乐播放器,如果可能的话,我想从设备中读取 .mp3 文件。

【问题讨论】:

    标签: cordova phonegap-plugins cordova-plugin-file


    【解决方案1】:

    您可以使用 Cordova 的 FileSystem 插件https://github.com/apache/cordova-plugin-file,并像这样在 DeviceReady 事件中访问外部存储

     window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, onFileSystemSuccess, function(){alert("fail");}); 
    

    然后你可以移动到不同的目录创建阅读器并使用 readEntries 方法读取它们的条目。

    例如,读取外部存储中的所有目录搜索“DCIM”目录

    function onFileSystemSuccess(fileSystem) {
        var directoryReader = fileSystem.createReader();
        directoryReader.readEntries(function (entries) {
            var i;
            for (i = 0; i < entries.length; i++) {
                if (entries[i].name === "DCIM") {
                    var dcimReader = entries[i].createReader();
                    dcimReader.readEntries(onGetDCIM, function () {
            window.console.log("fail");
        });
                    break; // remove this to traverse through all the folders and files
                }
            }
        }, function () {
            window.console.log("fail");
        });
    }
    

    阅读 fileSystem 插件以获得更多示例和文档

    【讨论】:

    • 非常感谢)你节省了我的时间))
    猜你喜欢
    • 2012-08-09
    • 2011-05-02
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    • 1970-01-01
    • 2021-05-07
    相关资源
    最近更新 更多