diff --git a/assets/gap.js b/assets/gap.js index 871efb9f..4c092701 100644 --- a/assets/gap.js +++ b/assets/gap.js @@ -310,8 +310,8 @@ var Device = { file: { result: "", - testSaveLocationExists: function(){ - Device.file.result = window.DroidGap.testSaveLocationExists(); + getFreeDiskSpace: function(){ + Device.file.result = window.DroidGap.getFreeDiskSpace(); return Device.file.result; }, testFileExists: function(file){ diff --git a/assets/index.html b/assets/index.html index 9fdc6479..e5913d62 100644 --- a/assets/index.html +++ b/assets/index.html @@ -1,5 +1,6 @@ - + + @@ -110,8 +111,8 @@ http = function(func) } fileManagement = function(x){ - if (x == 'testSDCard'){ - $('file_status').value = Device.file.testSaveLocationExists(); + if (x == 'getFreeDiskSpace'){ + $('file_status').value = Device.file.getFreeDiskSpace(); }else if (x == 'testFileExists'){ $('file_status').value = Device.file.testFileExists($('checkfile').value); @@ -175,7 +176,9 @@ phInformation = function(){ addLoadEvent(initGap); - + + +

Main

@@ -352,33 +355,34 @@ addLoadEvent(initGap);
- testSaveLocation + getFreeDiskSpace
testFileExists - +
testDirExists - +
-
- Create Directory - -
-
- Delete File - -
-
- - Delete Directory -
- - +
+ Create Directory + +
+
+ Delete File + +
+
+ + Delete Directory +
+ +

Audio

+

Make sure your Android sdk sdcard is mounted!

@@ -408,9 +412,10 @@ addLoadEvent(initGap); getAudioDevice
-
-
- + + + +
@@ -436,6 +441,9 @@ addLoadEvent(initGap);
- - -
+
+ + + + + diff --git a/src/com/nitobi/phonegap/DirectoryManager.java b/src/com/nitobi/phonegap/DirectoryManager.java index 47817b68..61d81a92 100644 --- a/src/com/nitobi/phonegap/DirectoryManager.java +++ b/src/com/nitobi/phonegap/DirectoryManager.java @@ -3,6 +3,7 @@ package com.nitobi.phonegap; import java.io.File; import android.os.Environment; +import android.os.StatFs; public class DirectoryManager { @@ -19,6 +20,25 @@ public class DirectoryManager { 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){ boolean status; if ((testSaveLocationExists())&&(!directoryName.equals(""))){ @@ -98,8 +118,8 @@ public class DirectoryManager { }else status = false; return status; - } + private File constructFilePaths (String file1, String file2){ File newPath; newPath = new File(file1+"/"+file2); diff --git a/src/com/nitobi/phonegap/PhoneGap.java b/src/com/nitobi/phonegap/PhoneGap.java index 36d0ce73..05988669 100644 --- a/src/com/nitobi/phonegap/PhoneGap.java +++ b/src/com/nitobi/phonegap/PhoneGap.java @@ -259,6 +259,12 @@ public class PhoneGap{ else return 1; } + + public long getFreeDiskSpace(){ + System.out.println("FOOOOOOOO"); + long freeDiskSpace=fileManager.getFreeDiskSpace(); + return freeDiskSpace; + } public int testFileExists(String file){ if (fileManager.testFileExists(file))