在我的应用中,我必须让用户选择保存某些文件的位置。它必须从SD卡或内存中选择。
我尝试做一些像这样的测试导演:
对于Sd-card
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/External dir");
dir.mkdirs();
内部
File path2 = Environment.getDataDirectory();
File dir22 = new File (path2.getAbsolutePath() + "/Internal dir");
dir22.mkdirs();
我也试试:
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
double sdAvailSize = (double)stat.getAvailableBlocks()*(double)stat.getBlockSize();
double mb= sdAvailSize / (1024*1024);
Log.w("sd-card",""+mb); //show me that i have 1240 mb on sd-card
和
File path = Environment.getDataDirectory();
StatFs stats = new StatFs(path.getPath());
int availableBlocks = stats.getAvailableBlocks();
int blockSizeInBytes = stats.getBlockSize();
int freeSpaceInBytes = availableBlocks * blockSizeInBytes;
double mb2= (availableBlocks*blockSizeInBytes)/(1024*1024);
Log.w("telephone",""+mb2); ///shows me 283 mb on phone
为什么?