让所有Android上的总的和可用空间 [英] Getting all the total and available space on Android

查看:146
本文介绍了让所有Android上的总的和可用空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,在Android上,有:

To my knowledge, on Android, there is:

  • 在内部存储器中的应用程序和缓存
  • 在某些手机内部SD卡(不可拆卸)
  • 在外接SD卡音乐和照片(可移动)

我如何与他们存在的检查(有些手机没有内置SD卡)

How do I get the total and available for each with a check that they exist (some phones do not have an internal SD Card)

感谢

推荐答案

下面是你如何让内部存储大小:

Here is how you get internal storage sizes:

 StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());        
 long blockSize = statFs.getBlockSize();
 long totalSize = statFs.getBlockCount()*blockSize;
 long availableSize = statFs.getAvailableBlocks()*blockSize;
 long freeSize = statFs.getFreeBlocks()*blockSize;

下面是你如何获得外部存储大小(SD卡大小):

Here is how you get external storage sizes (SD card size):

 StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());        
 long blockSize = statFs.getBlockSize();
 long totalSize = statFs.getBlockCount()*blockSize;
 long availableSize = statFs.getAvailableBlocks()*blockSize;
 long freeSize = statFs.getFreeBlocks()*blockSize;


便签

免费块:

块的总数是   自由的文件系统,包括上   保留块(即不   适用于正常的应用程序)。

The total number of blocks that are free on the file system, including reserved blocks (that are not available to normal applications).

可用块:

块是免费数   文件系统并提供给   应用程序。

The number of blocks that are free on the file system and available to applications.

下面是如何检测SD卡是否被安装:


Here is how to detect whether SD card is mounted:

 String state = Environment.getExternalStorageState();
 if (Environment.MEDIA_MOUNTED.equals(state)) 
 {
   // We can read and write the media    
 } 
 else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) 
 {
    // We can only read the media     
 } 
 else 
 {
    // No external media
 }

这篇关于让所有Android上的总的和可用空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆