android获取手机存储空间信息

利用Environment.getExternalStorageState()来获取手机剩余内存和总内存
totalSeize是总内存
aaa是手机剩余内存

private long getSDCardAvailSize() {    
    String state = Environment.getExternalStorageState();  
    long aaa=0;    
    if (Environment.MEDIA_MOUNTED.equals(state)) {      
        File sdcardDir = Environment.getExternalStorageDirectory();        
        StatFs sf = new StatFs(sdcardDir.getPath());     
        long blockSize = sf.getBlockSize(); 
        long blockCount = sf.getBlockCount();      
        long availCount = sf.getAvailableBlocks();     
        long totalSeize = blockSize * blockCount;     
        aaa = availCount * blockSize;      
        Log.e("size", "block大小:" + blockSize + ",block数目:" + blockCount + ",总大小:" + blockSize * blockCount / 1024 + "KB");  
        Log.e("size", "可用的block数目::" + availCount + ",剩余空间:" + availCount * blockSize / 1024 + "KB"); 
    }   
    return aaa;
}

你可能感兴趣的:(android获取手机存储空间信息)