zoukankan      html  css  js  c++  java
  • Android获取手机内存和sd卡相关信息

    1、手机内存已用和可用空间

     1 private String[] getPhoneMemory() {   
     2         String[] result = {"",""};  //1-total 2-avail   
     3         ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();    
     4         ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
     5 
     6         am.getMemoryInfo(mi);     
     7         long mTotalMem = 0;   
     8         long mAvailMem = mi.availMem;   
     9         String str1 = "/proc/meminfo";   
    10         String str2;   
    11         String[] arrayOfString;   
    12         try {   
    13             FileReader localFileReader = new FileReader(str1);   
    14             BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);   
    15             str2 = localBufferedReader.readLine();   
    16             arrayOfString = str2.split("\s+");   
    17             mTotalMem = Integer.valueOf(arrayOfString[1]).intValue() * 1024;   
    18             localBufferedReader.close();   
    19         } catch (IOException e) {   
    20             e.printStackTrace();   
    21         }   
    22         result[0] = Formatter.formatFileSize(this, mTotalMem);   
    23         result[1] = Formatter.formatFileSize(this, mAvailMem);   
    25         return result;    
    26 }  

    2、sd卡已用和可用空间

    1 public long getAvailaleSize() {// sd卡信息(可用)
    2         File path = Environment.getExternalStorageDirectory(); // 取得sdcard文件路径
    3         StatFs stat = new StatFs(path.getPath());
    4         long blockSize = stat.getBlockSize();
    5         long availableBlocks = stat.getAvailableBlocks();
    6         return availableBlocks * blockSize/1024 /1024;
    9     }
    1     public long getAllSize() {//总大小
    2         File path = Environment.getExternalStorageDirectory();
    3         StatFs stat = new StatFs(path.getPath());
    4         long blockSize = stat.getBlockSize();
    5         long availableBlocks = stat.getBlockCount();
    6         return availableBlocks * blockSize/1024 /1024;
    7     }
  • 相关阅读:
    Hopcroft-Carp 算法模板 自用
    (转)二分图匹配匈牙利算法与KM算法
    LightOJ
    最短路类型 (至今做过的)
    POJ
    POJ
    差分约束
    传递闭包(例题POJ3660)
    arrow,
    分辨率,
  • 原文地址:https://www.cnblogs.com/snowspace/p/3297813.html
Copyright © 2011-2022 走看看