안드로이드 개발 질문/답변
(글 수 45,052)
제목과 동일하게 현재 사용하고 있는 Storage의 남은 용량을 체크하고 싶습니다.
API 문서를 검색해보았지만 찾을 수 가 없네요.
고수님들의 도움 부탁드립니다. ^^
2010.07.05 17:07:02
android.os.Environment.getExternalStorageState() 이 함수 리턴값이
이렇게 밖에 없더군요. 용량을 리턴해주지는 않아서요. 용량을 체크한 다음 DB에 값을 넣을 지를 결정하려고 합니다.
String | MEDIA_BAD_REMOVAL | getExternalStorageState() returns MEDIA_BAD_REMOVAL if the media was removed before it was unmounted. |
String | MEDIA_CHECKING | getExternalStorageState() returns MEDIA_CHECKING if the media is present and being disk-checked |
String | MEDIA_MOUNTED | getExternalStorageState() returns MEDIA_MOUNTED if the media is present and mounted at its mount point with read/write access. |
String | MEDIA_MOUNTED_READ_ONLY | getExternalStorageState() returns MEDIA_MOUNTED_READ_ONLY if the media is present and mounted at its mount point with read only access. |
String | MEDIA_NOFS | getExternalStorageState() returns MEDIA_NOFS if the media is present but is blank or is using an unsupported filesystem |
String | MEDIA_REMOVED | getExternalStorageState() returns MEDIA_REMOVED if the media is not present. |
String | MEDIA_SHARED | getExternalStorageState() returns MEDIA_SHARED if the media is present not mounted, and shared via USB mass storage. |
String | MEDIA_UNMOUNTABLE | getExternalStorageState() returns MEDIA_UNMOUNTABLE if the media is present but cannot be mounted. |
String | MEDIA_UNMOUNTED | getExternalStorageState() returns MEDIA_UNMOUNTED if the media is present but not mounted. |
이렇게 밖에 없더군요. 용량을 리턴해주지는 않아서요. 용량을 체크한 다음 DB에 값을 넣을 지를 결정하려고 합니다.
2010.07.05 17:57:03
Setting 에서 는 이렇게 해주더 군요 (필요한 부분만 발췌해 보았습니다.)
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long availableBlocks = stat.getAvailableBlocks();
// SdSize
formatSize(totalBlocks * blockSize);
// mSdAvail
formatSize(availableBlocks * blockSize) + readOnly;
private String formatSize(long size) {
return Formatter.formatFileSize(this, size);
}
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long availableBlocks = stat.getAvailableBlocks();
// SdSize
formatSize(totalBlocks * blockSize);
// mSdAvail
formatSize(availableBlocks * blockSize) + readOnly;
private String formatSize(long size) {
return Formatter.formatFileSize(this, size);
}
API가 있을것 같은데 말이죠^^