Android get free size of internal/external memory

前端 未结 13 1007
眼角桃花
眼角桃花 2020-11-22 15:20

I want to get the size of free memory on internal/external storage of my device programmatically. I\'m using this piece of code :

StatFs stat = new StatFs(En         


        
相关标签:
13条回答
  • 2020-11-22 15:51

    This is the way I did it :

    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    long bytesAvailable;
    if (android.os.Build.VERSION.SDK_INT >= 
        android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        bytesAvailable = stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
    }
    else {
        bytesAvailable = (long)stat.getBlockSize() * (long)stat.getAvailableBlocks();
    }
    long megAvailable = bytesAvailable / (1024 * 1024);
    Log.e("","Available MB : "+megAvailable);
    
    0 讨论(0)
提交回复
热议问题