本文介绍了如何获得外部存储SD卡的大小(用安装SD卡)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Link :我根据这个链接制作

我说这条线找到的大小(内部和外部)的大小,

I added this line to find the size (both Internal and External) size,

return availableExternalMemorySize/(1024*1024);

我在我的平板电脑进行测试。我得到的内部和外部SD卡大小,

I tested in my Tablet. I am getting both Internal and External SD card size as,

在内部存储,1)总记忆--10072)可用内存--683

In Internal Storage,1)Total Memory --10072)Available Memory --683

在外部存储,1)总的内存 - 17632)可用内存 - 1554

In External Storage,1)Total Memory -- 17632)Available Memory -- 1554

但在平板电脑上,我看到settings.An外部存储设备大小有8GB。但它显示了我1.7 GB,当我通过编程方式进行测试。

But in Tablet, I saw settings.An External Storage size has 8GB. But it is showing me 1.7 GB around when I tested via programmatically..

的程序是什么,以找到一个外部存储大小?

What is the procedure to find an External storage size?

请好心的人建议/帮助我吗?

Please kindly anyone suggest / help me ?

谢谢!

推荐答案

要获得外部SD卡的用自由空间来显示一些它同意菜单 - >设置 - > SD卡和手机存储的号码,使用以下code:

To get the external SD card's available "free" space to show a number which agrees with the Menu->Settings->SD card and phone storage's number, use the following code:

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
double sdAvailSize = (double)stat.getAvailableBlocks()
                   * (double)stat.getBlockSize();
//One binary gigabyte equals 1,073,741,824 bytes.
double gigaAvailable = sdAvailSize / 1073741824;

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

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;


便签

免费块:

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

可用块:

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

下面是如何检测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
 }

相关文章:http://developer.android.com/reference/android/os/StatFs.html

这篇关于如何获得外部存储SD卡的大小(用安装SD卡)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 19:43
查看更多