共通コードリファレンス(SDCard)
3994 ワード
package com.fredric.util;
/*-
* SD
*/
import java.io.File;
import android.os.Environment;
import android.os.StatFs;
public class SDCardUtils {
// SA
//Environment android
//MEDIA_MOUNTED SD
//MEDIA_REMOVED
//MEDIA_UNMOUNTED ,
//MEDIA_BAD_REMOVAL SD
//MEDIA_CHECKING
//MEDIA_SHARED USB
//MEDIA_UNMOUNTABLE
public static boolean isSDCardEnable(){
return Environment.getExternalStorageState()
.equals(Environment.MEDIA_MOUNTED);
}
// SD
public static String getSDCardPath(){
return Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator; // '/'
}
// SA ( M)
public static long getSDCardSize(){
if(isSDCardEnable()){
StatFs stat = new StatFs(getSDCardPath());
//getBlockCount SD block
//getAvailableBlocks SD block
long num = (long) stat.getAvailableBlocks();
long size = (long)stat.getBlockSize();
return (num * size)/1024/1024;
}else{
return 0;
}
}
}