Android:Example:DirectoryManager
Android에서 사용할 수 있는 미리 정의된 디렉터리 목록을 획득할 수 있다.
package ---;
import java.io.File;
import android.content.Context;
import android.os.Environment;
/**
* 안드로이드에서 사용할 수 있는 미리 정의된 디렉토리 목록을 획득할 수 있도록 도와준다.
*
* @author cwlee
* @since 2013-08-08
*/
public class DirectoryManager {
/** 생성자를 지원하지 않는다. */
protected DirectoryManager() {
throw new UnsupportedOperationException();
}
// -----------------------
// 내부저장소에 대한 지원.
// -----------------------
/** 캐시 저장영역 디렉터리 반환. */
public static File getCacheDir(Context c) {
return c.getCacheDir();
}
/** 특정(dbname)데이터베이스 파일 반환. */
public static File getDatabase(Context c, String dbname) {
return c.getDatabasePath(dbname);
}
/** 일반파일 디렉터리 반환. */
public static File getCommonFileDir(Context c) {
return c.getFilesDir();
}
/** 특정(filename) 일반파일 반환. */
public static File getCommonFile(Context c, String filename) {
return c.getFileStreamPath(filename);
}
// ----------------------------------
// 외부저장소중 공용영역에 대한 지원.
// ----------------------------------
/** 외부저장소(일반적으로 SD-CARD)의 최상위 디렉터리 반환. */
public static File getRoot() {
return Environment.getExternalStorageDirectory();
}
/** 알람으로 사용할 오디오파일 저장소 디렉터리. */
public static File getAlarms() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS);
}
/** 카메라로 촬영한 사진이 저장되는 디렉터리. */
public static File getDcim() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
}
/** 다운로드한 파일의 저장되는 디렉터리. */
public static File getDownloads() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
}
/** 음악파일 디렉터리. */
public static File getMusic() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
}
/** 영상파일 디렉터리. */
public static File getMovies() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
}
/** 알림음 오디오 디렉터리. */
public static File getNotifications() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS);
}
/** 그림파일 디렉터리. */
public static File getPictures() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
}
/** 팟캐스트(Podcast) 디렉터리. */
public static File getPodcasts() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS);
}
// -----------------------------------------------
// 외부저장소중 어플리케이션 고유영역에 대한 지원.
// -----------------------------------------------
/** 외부저장소중 어플리케이션 고유영역의 알람으로 사용할 오디오파일 저장소 디렉터리. */
public static File getAlarms(Context c) {
return c.getExternalFilesDir(Environment.DIRECTORY_ALARMS);
}
/** 외부저장소중 어플리케이션 고유영역의 카메라로 촬영한 사진이 저장되는 디렉터리. */
public static File getDcim(Context c) {
return c.getExternalFilesDir(Environment.DIRECTORY_DCIM);
}
/** 외부저장소중 어플리케이션 고유영역의 다운로드한 파일의 저장되는 디렉터리. */
public static File getDownloads(Context c) {
return c.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
}
/** 외부저장소중 어플리케이션 고유영역의 음악파일 디렉터리. */
public static File getMusic(Context c) {
return c.getExternalFilesDir(Environment.DIRECTORY_MUSIC);
}
/** 외부저장소중 어플리케이션 고유영역의 영상파일 디렉터리. */
public static File getMovies(Context c) {
return c.getExternalFilesDir(Environment.DIRECTORY_MOVIES);
}
/** 외부저장소중 어플리케이션 고유영역의 알림음 오디오 디렉터리. */
public static File getNotifications(Context c) {
return c.getExternalFilesDir(Environment.DIRECTORY_NOTIFICATIONS);
}
/** 외부저장소중 어플리케이션 고유영역의 그림파일 디렉터리. */
public static File getPictures(Context c) {
return c.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
}
/** 외부저장소중 어플리케이션 고유영역의 팟캐스트(Podcast) 디렉터리. */
public static File getPodcasts(Context c) {
return c.getExternalFilesDir(Environment.DIRECTORY_PODCASTS);
}
/** 외부저장소의 어플리케이션 고유영역의 캐시영역 디렉터리 반환. */
public static File getExternalCacheDir(Context c) {
return c.getExternalCacheDir();
}
}