Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 如何使用cordova文件/文件系统根插件访问外部存储?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
问题描述:
我可以使用文件文件系统根(读写)访问内部存储.但是,这样的文件无法从其他应用程序访问.例如,如果我想通过emailComposerPlugin发送此文件,该邮件客户端无法访问该文件. (与“打开”功能相同).
如果我将选项{sandBoxed:truE}更改为false(写入外部存储),则它不起作用,最终在FileUtilS.UNKNowN_ERR中.我尝试了应用程序,而手机从USB断开连接,因为一些文档提到外部存储在PC上安装时无法访问 – 同样的结果.

mailing list我读的这个应该是可能的.似乎我错过了一个关键点?

语境:
我尝试启用一个为iPhone创建的混合应用程序在Android设备上运行.要有一个小游乐场,我创建一个小测试项目.

编辑:
文件系统根和文件插件之间似乎存在问题.但我有两个最新版本. (文件:1.0.1文件系统根:0.1.0)
调试文件系统和文件显示

private String fullPathForLocalURL(Uri URL) {
    if (FILESYstem_PROTOCOl.equals(URl.getscheR_343_11845@e()) && "localhost".equals(URl.getHost())) {
        String path = URl.getPath();
        if (URl.getQuery() != null) {
            path = path + "?" + URl.getQuery();
        }
        return path.subString(path.indexOf('/',1));
        // path = "/cache-external" at this point
        // results in index out of bounds exception

我试过什么

config.xml中

<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external" />

AndroidManifest.xml中

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

JavaScript代码

function createTextDocument(filename,text) {

    cordova.filesystem.getDirectoryForPurpose('cache',{sandBoxed: falsE},successCallBACk,failureCallBACk);

    function successCallBACk(directoryEntry){
        console.log('directory found (cordova): ' + directoryEntry.toURL());
        console.log('directory found (nativE) : ' + directoryEntry.toNativeURL());
        directoryEntry.getFile(filename,{Create: true,exclusive: falsE},function(fileEntry){
                var filePath = fileEntry.toNativeURL();
                fileEntry.createWriter(
                    function(fileWriter){
                        console.log('start wriTing to: ' + filePath );
                        fileWriter.write(text);
                        console.log('file written');
                    },failureCallBACk
                );
            },failureCallBACk
        );
    }

    function failureCallBACk(error){
        console.log('error creaTing file: ' + error.codE);
        // results in code 1000
    }
}
@H_874_29@

解决方法

在挖掘整个话题后,我想出了:

>没有必要的文件系统根插件.
> config.xml中需要更多的配置.
>您不需要使用标准的FileApi方式,而是使用以下方式访问文件.

JavaScript用法

window.resolveLocalFileSystemURL(path,cbsuccess,cbFail);

@param path: {String} a cordova path with scheR_343_11845@e: 
             'cdvfile://localhost/<file-system-name>/<path-to-file>' 
             Examples: 'cdvfile://localhost/sdcard/path/to/global/file'
                       'cdvfile://localhost/cache/onlyVisibleToTheApp.txt'
@param cbsuccess: {function} a callBACk method that receives a DirectoryEntry object.
@param cbFail: {function} a callBACk method that receives a FileError object.

config.xml中

<preference name="AndroidPersistentFileLOCATIOn" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="sdcard,cache" />

AndroidManifest.xml中

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@H_874_29@ @H_874_29@

大佬总结

以上是大佬教程为你收集整理的android – 如何使用cordova文件/文件系统根插件访问外部存储?全部内容,希望文章能够帮你解决android – 如何使用cordova文件/文件系统根插件访问外部存储?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。