如何获取SD卡的大小
public class DemoActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); //每一个区块的大小 long totalBlocks = stat.getBlockCount(); //所有区块 long availableBlocks = stat.getAvailableBlocks(); // 所有可用区块 String totalsize = Formatter.formatFileSize(this, totalBlocks * blockSize); String availablesize = Formatter.formatFileSize(this, availableBlocks * blockSize); TextView tv = new TextView(this); tv.setText("sd卡大小"+totalsize+"\n"+"可用空间"+availablesize); setContentView(tv); }}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。