【问题标题】:Cordova - How to access Device Storage?Cordova - 如何访问设备存储?
【发布时间】:2019-08-16 15:23:12
【问题描述】:

我正在开发一个包含 MP3 播放器的 cordova 应用程序,为此,我必须获取设备中的所有 MP3 文件,我知道如何在 SDCard 中搜索(使用 cordova.file.externalRootDirectory)但是,如何访问到经典的设备存储? (哪里有“Android”、“DCIM”、“Download”...文件夹)

提前致谢。

编辑:cordova.file.dataDirectory 不起作用

【问题讨论】:

    标签: javascript android html css cordova


    【解决方案1】:

    我正在使用插件cordova-plugin-file,它可以让我访问内部文件存储

    var folderpath = cordova.file.dataDirectory + "Download/";
    

    Android 目录结构

    • files:应用程序的内部文件存储目录
    • files-external:应用程序的外部文件存储目录
    • sdcard:全局外部文件存储目录(如果已安装,则为 SD 卡的根目录)。您必须拥有 android.permission.WRITE_EXTERNAL_STORAGE 权限才能使用它。
    • 缓存:应用程序的内部缓存目录
    • cache-external:应用程序的外部缓存目录
    • assets:应用程序包(只读)
    • root:整个设备文件系统
    • applicationDirectory:只读,访问受限。可以复制此目录中的文件,但直接读取会导致“找不到文件”。 Android 还支持名为“documents”的特殊文件系统,它表示“files”文件系统中的“/Documents/”子目录。

    更多信息在Apache doc

    【讨论】:

    • 我它给了我一个错误,这是我的代码:window.resolveLocalFileSystemURL(cordova.file.dataDirectory+'Music/', function (fileSystem) { var reader = fileSystem.createReader(); reader.readEntries( function (entries) { navigator.notification.alert('Entry: '+entries, null, 'RedSet', 'OK'); }, function (err) { navigator.notification.alert('Err! '+err, null, 'RedSet', 'OK'); }); }, function (err) { navigator.notification.alert('Error! '+err, null, 'RedSet', 'OK'); });
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    • 2022-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多