안드로이드 내부저장소(Internal Storage) 사용량 구하기 , 저장소 전체용량 , 저장소 사용가능 용량


MainActivity.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    //내부저장소(Internal Storage) 사용량 구하기
    public String getInternalUsageRate(){
        String path = Environment.getDataDirectory().getAbsolutePath();
        StatFs stat = new StatFs(path);
 
        long blockSize = stat.getBlockSizeLong();   //API 18부터
        //전체 Internal Storage 크기
        long totalSize = stat.getBlockCountLong() * blockSize;   //API 18부터
        //사용가능한 Internal Storage 크기
        long availableSize = stat.getAvailableBlocksLong() * blockSize;   //API 18부터
 
        //사용량
        DecimalFormat df = new DecimalFormat("#,###");
        double storage = 100.0*(totalSize-availableSize)/totalSize;
        return df.format(storage)+"%";
    }
cs



결과


+ Recent posts