1

In my app I must let the user to choose where to save some files. It must choose from sd-card or internal memory.

I try to make some test directorys like this :

For Sd-card

  File sdCard = Environment.getExternalStorageDirectory();
  File dir = new File (sdCard.getAbsolutePath() + "/External dir");
  dir.mkdirs();

For internal

File path2 = Environment.getDataDirectory();
File dir22 = new File (path2.getAbsolutePath() + "/Internal dir");
dir22.mkdirs();
  1. Only the 'External dir' is made. The 'Internal dir' does not. Also I have install on my phone 'OI File Manager' and also I can not make any dir on the internal storage
  2. My phone does not have any Sd-card at all. The code above does not give my any errors about no sd-card.

Also I try :

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

and

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

Why is that?

rene
  • 41,474
  • 78
  • 114
  • 152
Huliganul
  • 71
  • 1
  • 9
  • read this carefully http://stackoverflow.com/a/21230946/3529488 – Robust Apr 20 '15 at 11:05
  • First learn about difference between various storages: http://stackoverflow.com/questions/5092591/what-are-the-differences-among-internal-storage-external-storage-sd-card-and-r/29427958#29427958 – Vikasdeep Singh Apr 20 '15 at 11:11
  • I've edited your title. See [Should questions include “tags” in their titles?](http://meta.stackoverflow.com/a/130208/158100) where the consensus is "no, they should not". – rene Apr 20 '15 at 11:51

0 Answers0