mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
File IO getFreeDiskSpace()
This commit is contained in:
parent
dfa2f0a802
commit
49844b4e39
@ -310,8 +310,8 @@ var Device = {
|
|||||||
|
|
||||||
file: {
|
file: {
|
||||||
result: "",
|
result: "",
|
||||||
testSaveLocationExists: function(){
|
getFreeDiskSpace: function(){
|
||||||
Device.file.result = window.DroidGap.testSaveLocationExists();
|
Device.file.result = window.DroidGap.getFreeDiskSpace();
|
||||||
return Device.file.result;
|
return Device.file.result;
|
||||||
},
|
},
|
||||||
testFileExists: function(file){
|
testFileExists: function(file){
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
||||||
|
|
||||||
|
|
||||||
@ -110,8 +111,8 @@ http = function(func)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fileManagement = function(x){
|
fileManagement = function(x){
|
||||||
if (x == 'testSDCard'){
|
if (x == 'getFreeDiskSpace'){
|
||||||
$('file_status').value = Device.file.testSaveLocationExists();
|
$('file_status').value = Device.file.getFreeDiskSpace();
|
||||||
}else
|
}else
|
||||||
if (x == 'testFileExists'){
|
if (x == 'testFileExists'){
|
||||||
$('file_status').value = Device.file.testFileExists($('checkfile').value);
|
$('file_status').value = Device.file.testFileExists($('checkfile').value);
|
||||||
@ -175,7 +176,9 @@ phInformation = function(){
|
|||||||
addLoadEvent(initGap);
|
addLoadEvent(initGap);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head><body orient="landscape">
|
</head>
|
||||||
|
|
||||||
|
<body orient="landscape">
|
||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<h1 id="pageTitle">Main</h1>
|
<h1 id="pageTitle">Main</h1>
|
||||||
<a style="display: none;" id="backButton" class="button" href="#"></a>
|
<a style="display: none;" id="backButton" class="button" href="#"></a>
|
||||||
@ -352,33 +355,34 @@ addLoadEvent(initGap);
|
|||||||
<input disabled="enabled" name="file_status" id="file_status" value="" type="text"></input>
|
<input disabled="enabled" name="file_status" id="file_status" value="" type="text"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<a class="button leftButton" type="submit" onclick="fileManagement('testSDCard');">testSaveLocation</a>
|
<a class="button leftButton" type="submit" onclick="fileManagement('getFreeDiskSpace');">getFreeDiskSpace</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<a class="button leftButton" type="submit" onclick="fileManagement('testFileExists')">testFileExists</a>
|
<a class="button leftButton" type="submit" onclick="fileManagement('testFileExists')">testFileExists</a>
|
||||||
<input type=text name="checkfile" id="checkfile" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
<input type=text name="checkfile" id="checkfile" value="/hullophonegap.mp3" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<a class="button leftButton" type="submit" onclick="fileManagement('testDirectoryExists')">testDirExists</a>
|
<a class="button leftButton" type="submit" onclick="fileManagement('testDirectoryExists')">testDirExists</a>
|
||||||
<input type=text name="checkdir" id="checkdir" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
<input type=text name="checkdir" id="checkdir" value="/foo" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<a class="button leftButton" type="submit" onclick="fileManagement('createDir');">Create Directory</a>
|
<a class="button leftButton" type="submit" onclick="fileManagement('createDir');">Create Directory</a>
|
||||||
<input type=text name="createfile" id="createfile" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
<input type=text name="createfile" id="createfile" value="/foo" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<a class="button leftButton" type="submit" onclick="fileManagement('delFile');">Delete File</a>
|
<a class="button leftButton" type="submit" onclick="fileManagement('delFile');">Delete File</a>
|
||||||
<input type=text name="delfile" id="delfile" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
<input type=text name="delfile" id="delfile" value="/hullophonegap.mp3" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<input type=text name="deldir" id="deldir" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
<input type=text name="deldir" id="deldir" value="/foo" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
||||||
<a class="button leftButton" type="submit" onclick="fileManagement('delDir');">Delete Directory</a>
|
<a class="button leftButton" type="submit" onclick="fileManagement('delDir');">Delete Directory</a>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="audio" title="audio" class="panel">
|
<div id="audio" title="audio" class="panel">
|
||||||
<h2>Audio</h2>
|
<h2>Audio</h2>
|
||||||
|
<p><i>Make sure your Android sdk sdcard is mounted!</i></p>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label>AudioFile:</label>
|
<label>AudioFile:</label>
|
||||||
@ -408,9 +412,10 @@ addLoadEvent(initGap);
|
|||||||
<a class="button leftButton" type="submit" onclick="audio('getAudioOutputDevice');">getAudioDevice</a>
|
<a class="button leftButton" type="submit" onclick="audio('getAudioOutputDevice');">getAudioDevice</a>
|
||||||
<input disabled="enabled" id="audoutput" type="text" style="width: 30ex"/>
|
<input disabled="enabled" id="audoutput" type="text" style="width: 30ex"/>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="pi" title="Phone Information" class="panel">
|
<div id="pi" title="Phone Information" class="panel">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -436,6 +441,9 @@ addLoadEvent(initGap);
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="preloader"></div>
|
||||||
|
|
||||||
<div id="preloader"></div></body></html>
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.nitobi.phonegap;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.StatFs;
|
||||||
|
|
||||||
public class DirectoryManager {
|
public class DirectoryManager {
|
||||||
|
|
||||||
@ -19,6 +20,25 @@ public class DirectoryManager {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected long getFreeDiskSpace(){
|
||||||
|
/*
|
||||||
|
* gets the available SD card free space or returns -1 if the SD card is not mounted.
|
||||||
|
*/
|
||||||
|
String status = Environment.getExternalStorageState();
|
||||||
|
long freeSpace = 0;
|
||||||
|
if (status.equals(Environment.MEDIA_MOUNTED)) {
|
||||||
|
try {
|
||||||
|
File path = Environment.getExternalStorageDirectory();
|
||||||
|
StatFs stat = new StatFs(path.getPath());
|
||||||
|
long blockSize = stat.getBlockSize();
|
||||||
|
long availableBlocks = stat.getAvailableBlocks();
|
||||||
|
freeSpace = availableBlocks*blockSize/1024;
|
||||||
|
|
||||||
|
} catch (Exception e) {e.printStackTrace(); }
|
||||||
|
} else { return -1; }
|
||||||
|
return (freeSpace);
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean createDirectory(String directoryName){
|
protected boolean createDirectory(String directoryName){
|
||||||
boolean status;
|
boolean status;
|
||||||
if ((testSaveLocationExists())&&(!directoryName.equals(""))){
|
if ((testSaveLocationExists())&&(!directoryName.equals(""))){
|
||||||
@ -98,8 +118,8 @@ public class DirectoryManager {
|
|||||||
}else
|
}else
|
||||||
status = false;
|
status = false;
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private File constructFilePaths (String file1, String file2){
|
private File constructFilePaths (String file1, String file2){
|
||||||
File newPath;
|
File newPath;
|
||||||
newPath = new File(file1+"/"+file2);
|
newPath = new File(file1+"/"+file2);
|
||||||
|
@ -259,6 +259,12 @@ public class PhoneGap{
|
|||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getFreeDiskSpace(){
|
||||||
|
System.out.println("FOOOOOOOO");
|
||||||
|
long freeDiskSpace=fileManager.getFreeDiskSpace();
|
||||||
|
return freeDiskSpace;
|
||||||
|
}
|
||||||
|
|
||||||
public int testFileExists(String file){
|
public int testFileExists(String file){
|
||||||
if (fileManager.testFileExists(file))
|
if (fileManager.testFileExists(file))
|
||||||
|
Loading…
Reference in New Issue
Block a user