程序员一代码搬运工
【Java学习心得和Java学习技术个人总结】

Android获取SD卡总容量,可用大小,机身内存总容量及可用大小

publiclonggetSDTotalSize(){/*获取存储卡路径*/FilesdcardDir=Environment.getExternalStorageDirectory();/*Stat
public long getSDTotalSize()
{
    /*获取存储卡路径*/
    File sdcardDir= Environment.getExternalStorageDirectory();
    /*StatFs 看文件系统空间使用情况*/
    StatFs statFs=new StatFs(sdcardDir.getPath());
    long blockSize= statFs.getBlockSizeLong();
  
    long totalSize=statFs.getBlockCountLong();
  
    return blockSize*totalSize;
}
  
    /**
     * 获得sd卡剩余容量,即可以大小
     * @return
     */
    public long getSdAvaliableSize()
    {
        File path=Environment.getExternalStorageDirectory();
        StatFs statFs=new StatFs(path.getPath());
        long blockSize=statFs.getBlockSizeLong();
        long availableBlocks=statFs.getAvailableBlocksLong();
        return blockSize*availableBlocks;
    }
  
    /**
     * 获得机身内存大小
     * @return
     */
    public long getRomTotalSize()
    {
        File path=Environment.getDataDirectory();
        StatFs statFs=new StatFs(path.getPath());
        long blockSize=statFs.getBlockSizeLong();
        long tatalBlocks= statFs.getBlockCountLong();
     return blockSize*tatalBlocks;
    }
  
    /**
     * 获得机身可用内存
     * @return
     */
    private long getRomAvailableSize()
    {
        File path=Environment.getDataDirectory();
        StatFs statFs=new StatFs(path.getPath());
        long blockSize=statFs.getBlockSizeLong();
        long availableBlocks=statFs.getAvailableBlocksLong();
        return blockSize*availableBlocks;
    }

赞(0)
未经允许不得转载:程序员一代码搬运工 » Android获取SD卡总容量,可用大小,机身内存总容量及可用大小
分享到: 更多 (0)