获取sd卡的大小

it2026-02-14  16

1 2 3 4 5 6 7 8 9 TextView tv = (TextView) findViewById(R.id.tv_sdsize);          File path = Environment.getExternalStorageDirectory();          StatFs stat = new StatFs(path.getPath());          long blockSize = stat.getBlockSize();          long availableBlocks = stat.getAvailableBlocks();          long sizeAvailSize = blockSize * availableBlocks;          String str = Formatter.formatFileSize( this , sizeAvailSize);          tv.setText(str);      }

 以下是android系统设置查看sd卡大小的源码

1 2 3 4 5 6 7 8 9 10 11 12 File path = Environment.getExternalStorageDirectory();                  StatFs stat = new StatFs(path.getPath());                  long blockSize = stat.getBlockSize();                  long totalBlocks = stat.getBlockCount();                  long availableBlocks = stat.getAvailableBlocks();                                     mSdSize.setSummary(formatSize(totalBlocks * blockSize));                  mSdAvail.setSummary(formatSize(availableBlocks * blockSize) + readOnly);                     mSdMountToggle.setEnabled( true );                  mSdMountToggle.setTitle(mRes.getString(R.string.sd_eject));                  mSdMountToggle.setSummary(mRes.getString(R.string.sd_eject_summary));

 

 

 

 

 

 

来自为知笔记(Wiz)

转载于:https://www.cnblogs.com/feelbest/p/3696256.html

相关资源:stm32+fatfs+SDIO读写TF卡
最新回复(0)