흔히 이 소스를 다 이용한다하더라구요..

근데 이것을 어떻게 응용하는지 모르겠네요..

textview에 넣어서 화면에 아무거나 보여주려는데

어떻게 얻어오는지 제가 하는데 게속 잘안됩니다..ㅜㅜ

 

검색해도 응용소스가 안나오길래 질문 올립니다

    static final int ERROR = -1;
    
     static public boolean externalMemoryAvailable() {
         return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
     }
    
     static public long getAvailableInternalMemorySize() {
         File path = Environment.getDataDirectory();
         StatFs stat = new StatFs(path.getPath());
         long blockSize = stat.getBlockSize();
         long availableBlocks = stat.getAvailableBlocks();
         return availableBlocks * blockSize;
     }
    
     static public long getTotalInternalMemorySize() {
         File path = Environment.getDataDirectory();
         StatFs stat = new StatFs(path.getPath());
         long blockSize = stat.getBlockSize();
         long totalBlocks = stat.getBlockCount();
         return totalBlocks * blockSize;
     }
    
     static public long getAvailableExternalMemorySize() {
         if(externalMemoryAvailable()) {
             File path = Environment.getExternalStorageDirectory();
             StatFs stat = new StatFs(path.getPath());
             long blockSize = stat.getBlockSize();
             long availableBlocks = stat.getAvailableBlocks();
             return availableBlocks * blockSize;
         } else {
             return ERROR;
         }
     }
    
     static public long getTotalExternalMemorySize() {
         if(externalMemoryAvailable()) {
             File path = Environment.getExternalStorageDirectory();
             StatFs stat = new StatFs(path.getPath());
             long blockSize = stat.getBlockSize();
             long totalBlocks = stat.getBlockCount();
             return totalBlocks * blockSize;
         } else {
             return ERROR;
         }
     }
    
     static public String formatSize(long size) {
         String suffix = null;
    
         if (size >= 1024) {
             suffix = "KiB";
             size /= 1024;
             if (size >= 1024) {
                 suffix = "MiB";
                 size /= 1024;
             }
         }
    
         StringBuilder resultBuffer = new StringBuilder(Long.toString(size));
    
         int commaOffset = resultBuffer.length() - 3;
         while (commaOffset > 0) {
             resultBuffer.insert(commaOffset, ',');
             commaOffset -= 3;
         }
    
         if (suffix != null)
             resultBuffer.append(suffix);
         return resultBuffer.toString();
     }
 }