android 获取手机内存及SD卡内存可用空间

    xiaoxiao2024-12-25  14

    //1.获取内存可用大小,内存路径 String path=Environment.getDataDirectory().getAbsolutePath(); String memoryAvaliSpace= Formatter.formatFileSize(this,getAvailSpace(path)); //2.获取sd卡可用大小,sd卡路径 String sdPath=Environment.getExternalStorageDirectory().getAbsolutePath(); String sdAvaliSpace= Formatter.formatFileSize(this,getAvailSpace(sdPath)); private long getAvailSpace(String path) { //获取可用内存大小 StatFs statfs=new StatFs(path); //获取可用区块的个数 long count=statfs.getAvailableBlocks(); //获取区块大小 long size=statfs.getBlockSize(); //可用空间总大小 return count*size; }
    转载请注明原文地址: https://ju.6miu.com/read-1294984.html
    最新回复(0)