summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/util
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-12-30 22:03:55 +0100
committerdaniel oeh <daniel.oeh@gmail.com>2012-12-30 22:03:55 +0100
commitcd9d69d129959d4fc52a6854648e3ca8f1d4a9c1 (patch)
tree31f48508f8954fb81b06cbeb469dfec7143c4c78 /src/de/danoeh/antennapod/util
parent65491d5436e714d148cb337706e723ee5b62c83d (diff)
downloadAntennaPod-cd9d69d129959d4fc52a6854648e3ca8f1d4a9c1.zip
Updated storage availability check
Diffstat (limited to 'src/de/danoeh/antennapod/util')
-rw-r--r--src/de/danoeh/antennapod/util/StorageUtils.java47
1 files changed, 32 insertions, 15 deletions
diff --git a/src/de/danoeh/antennapod/util/StorageUtils.java b/src/de/danoeh/antennapod/util/StorageUtils.java
index d4738f14f..f32f51cef 100644
--- a/src/de/danoeh/antennapod/util/StorageUtils.java
+++ b/src/de/danoeh/antennapod/util/StorageUtils.java
@@ -1,41 +1,58 @@
package de.danoeh.antennapod.util;
+import java.io.File;
+
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.os.StatFs;
+import android.util.Log;
+import de.danoeh.antennapod.AppConfig;
+import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.activity.StorageErrorActivity;
/** Utility functions for handling storage errors */
public class StorageUtils {
- public static boolean storageAvailable() {
- String state = Environment.getExternalStorageState();
- return state.equals(Environment.MEDIA_MOUNTED);
+ private static final String TAG = "StorageUtils";
+
+ public static boolean storageAvailable(Context context) {
+ File dir = PodcastApp.getDataFolder(context, null);
+ if (dir != null) {
+ return dir.exists() && dir.canRead() && dir.canWrite();
+ } else {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Storage not available: data folder is null");
+ return false;
+ }
}
-
- /**Checks if external storage is available. If external storage isn't
- * available, the current activity is finsished an an error activity is launched.
- * @param activity the activity which would be finished if no storage is available
+
+ /**
+ * Checks if external storage is available. If external storage isn't
+ * available, the current activity is finsished an an error activity is
+ * launched.
+ *
+ * @param activity
+ * the activity which would be finished if no storage is
+ * available
* @return true if external storage is available
*/
public static boolean checkStorageAvailability(Activity activity) {
- boolean storageAvailable = storageAvailable();
+ boolean storageAvailable = storageAvailable(activity);
if (!storageAvailable) {
activity.finish();
- activity.startActivity(new Intent(activity, StorageErrorActivity.class));
+ activity.startActivity(new Intent(activity,
+ StorageErrorActivity.class));
}
return storageAvailable;
}
-
+
/** Get the number of free bytes that are available on the external storage. */
public static long getFreeSpaceAvailable() {
- StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
+ StatFs stat = new StatFs(Environment.getExternalStorageDirectory()
+ .getPath());
long availableBlocks = stat.getAvailableBlocks();
long blockSize = stat.getBlockSize();
return availableBlocks * blockSize;
}
-
- public static boolean externalStorageMounted() {
- return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
- }
}