summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/util/StorageUtils.java
blob: 942c333fb9a87f35fcc99f4af7aeb7739fb2f30f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package de.danoeh.antennapod.util;

import de.danoeh.antennapod.activity.StorageErrorActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Environment;

/** Utility functions for handling storage errors */
public class StorageUtils {
	public static boolean storageAvailable() {
		String state = Environment.getExternalStorageState();
		return state.equals(Environment.MEDIA_MOUNTED);
	}
	
	/**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();
		if (!storageAvailable) {
			activity.finish();
			activity.startActivity(new Intent(activity, StorageErrorActivity.class));
		}
		return storageAvailable;
	}
}