Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 有没有一种方法可以使用ApacheCordova专门了解根目录的可用空间(Android和iOS)?_Javascript_Android_Ios_Html_Cordova - Fatal编程技术网

Javascript 有没有一种方法可以使用ApacheCordova专门了解根目录的可用空间(Android和iOS)?

Javascript 有没有一种方法可以使用ApacheCordova专门了解根目录的可用空间(Android和iOS)?,javascript,android,ios,html,cordova,Javascript,Android,Ios,Html,Cordova,最近,我在实际工作中一直在研究这个话题,所有的研究都是针对这个可用字节函数的,您可以在下面看到: function onInitFs(fs) { var appDirectory = fs.root; window.alert("Directorio de trabajo: " + appDirectory.toURL()); availableBytes(function (free_bytes) { console.log("Interal free spac

最近,我在实际工作中一直在研究这个话题,所有的研究都是针对这个可用字节函数的,您可以在下面看到:

function onInitFs(fs) {
    var appDirectory = fs.root;
    window.alert("Directorio de trabajo: " + appDirectory.toURL());
    availableBytes(function (free_bytes) {
    console.log("Interal free space(root + internal): " + (free_bytes / (1024 * 1024 * 1024)).toFixed(0) + "GB");
 });
}
//Function used to know available space in internal storage
function availableBytes(callback, start, end) {
     callback = callback == null ? function () {} : callback
     start = start == null ? 0 : start
     end = end == null ? 1 * 1024 * 1024 * 1024 * 1024 : end 
     //starting with 1 TB
     limit = 1024 // precision of 1kb
     start_temp = start
     end_temp = end
     callback_temp = callback
     if (end - start < limit)
         callback(start)
     else {
         window.requestFileSystem(LocalFileSystem.PERSISTENT, parseInt(end_temp - ((end_temp - start_temp) / 2)), function (fileSystem) {
              setTimeout(function () {
                 availableBytes(callback_temp, parseInt(parseInt(end_temp - ((end_temp - start_temp) / 2))), end_temp)
        }, 0)
     }, function () {
        setTimeout(function () {
            availableBytes(callback_temp, start_temp, parseInt(end_temp - ((end_temp - start_temp) / 2)))
        }, 0)
     })
 }
}
函数onInitFs(fs){ var appDirectory=fs.root; window.alert(“Directorio de trabajo:+appDirectory.toURL()); 可用字节(函数(空闲字节){ log(“内部可用空间(根+内部):”+(可用字节/(1024*1024*1024)).toFixed(0)+“GB”); }); } //用于了解内部存储器中可用空间的函数 函数可用字节(回调、开始、结束){ callback=callback==null?函数(){}:callback start=start==null?0:开始 end=end==null?1*1024*1024*1024:end //从1 TB开始 限制=1024//1kb的精度 启动温度=启动 结束温度=结束 callback_temp=回调 if(结束-开始<极限) 回调(开始) 否则{ requestFileSystem(LocalFileSystem.PERSISTENT,parseInt(end_temp-((end_temp-start_temp)/2)),函数(fileSystem){ setTimeout(函数(){ 可用字节(回调临时、parseInt(parseInt(end临时-((end临时-start临时)/2))、end临时) }, 0) },函数(){ setTimeout(函数(){ 可用字节(回调临时、开始临时、解析int(结束临时-((结束临时-开始临时)/2))) }, 0) }) } }
正如您所见,我们可以很容易地知道内部存储的大小,但根存储(即我存储下载的视频和音乐的位置,客户端不容易访问的位置)无法“询问”,因此。。。有人知道这样做的正确方法吗?

为了获得设备的可用空间,您必须添加cordova文件插件:

然后,在设备就绪事件之后,可以运行以下代码:

cordova.exec(function(result) {
    alert("Free Disk Space: " + result);
}, function(error) {
    alert("Error: " + error);
}, "File", "getFreeDiskSpace", []);

这将以千字节为单位提醒总空间,只需将其转换为兆字节或千兆字节。

不知道是否有帮助,但当您尝试保存文件时,如果没有剩余空间,请求将失败,错误代码为10(超出配额)。这是一个很好的答案,但此函数提供的可用空间是内部存储器,而不是根存储,我将在根存储中存储应用程序下载的内容。我一直在考虑的是按照Akis所说的实现:*首先,我将尝试“编写”一个大文件,如果在编写时出现错误,我将递归调用同一个函数,直到它给出一个OK代码,这将是该特定存储空间的可用空间。@DavidTelegimTv是的,你是对的,我还发现了一个插件,上面写着它可以做你想做的事,但我从来没有用过,就是这个。如果你有时间,请核对一下