StorageTest

sd卡的一些狀態:http://lgz.iteye.com/blog/1308340

 

//獲取RAM總大小

private String getRamAvailMemory()

{

    String str1 = "/proc/meminfo":

    FileReader fr;

    try {

      fr = new FileReader(str1);

     BufferedReader localBufferedReader = new Buffered(fr,8192);

return localBufferedReader.readLine();

     } catch(IOException e) {

     return "";

    }

}

 

//獲取RAM可用大小

private String getRamAvailMemory()

{

    ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

   ActivityManager.MemoryInfo mi = new AcvityManager.MemoryInfo();

am.getMemoryInfo(mi);

      return Formatter.formatFileSize(this,mi.availMem);

}

 

//獲取內置存儲(USB存儲)大小

private String getEmmcMemory()

{

    StorageManager mSM = (StorageManager) getSystemServices()STORAGE_SERVICE);

   StorageVolume[] mSV= mSM.getVolumeList();

    for(int i=0;i<mSV.length;i++)

   {

         if(!mSV[i].isRemovable())

         {

               StatFs stat = new StatFs(mSV[i].getPath());

               long blockSize = stat.getBlockSize();

               long totalBlocks = stat.getBlockCount();

               return Formatter.formatFileSize(this,blockSize*totalBlocks);

         }

   }

    return "";

}

 

//獲得ROM總大小

private String getRomAvailMemory()

{

    File path = Environment.getDataDirectory();

   StatFs stat =  new StatFs(path.getPath());

    long blockSize = stat.getBlockSize();

     long totalBlocks = stat.getBlockCount();

      return Formatter.formatFileSize(this,blockSize*totalBlocks);

}

//獲得ROM可用大小

private String getRomAvailMemory()

{

    File path = Environment.getDataDirectory();

   StatFs stat =  new StatFs(path.getPath());

    long blockSize = stat.getBlockSize();

     long availBlocks= stat.getAvailableBlockCount();

      return Formatter.formatFileSize(this,blockSize*availBlocks);

}

//獲得SD卡總大小

private String getRomAvailMemory()

{

    File path = Environment.getExternalStorageDirectory();

   StatFs stat =  new StatFs(path.getPath());

    long blockSize = stat.getBlockSize();

     long totalBlocks = stat.getBlockCount();

      return Formatter.formatFileSize(this,blockSize*totalBlocks);

 

}

//獲得ROM可用大小

private String getRomAvailMemory()

{

    File path = Environment.getExternalStorageDirectory();

   StatFs stat =  new StatFs(path.getPath());

    long blockSize = stat.getBlockSize();

     long availBlocks= stat.getAvailableBlockCount();

      return Formatter.formatFileSize(this,blockSize*availBlocks);

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章