Android : when i measure external sdcard storage ,give output in negative figure in adroid

on Tuesday, September 16, 2014


i know this way i measure storage of my sdcard but i got storage byte in -ve figure


i don't know how my system give me -ve figure of storage


i got wrong figure in my external storage only but my internal storage give me perfect figure


i tested in api level 17


how i get original memory size of sdcard?


i am not apply Formatter.formatShor.... Log.d("sdcard", "Total 2:"+ tot0 ); becase it's not work for -ve number.


thanks in advance.


int tot0 = statFs0.getBlockCount() * block0;



//mysdcard path
StatFs statFs0 = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
int block0 = statFs0.getBlockSize();
int avail0 = statFs0.getAvailableBlocks() * block0;
int tot0 = statFs0.getBlockCount() * block0;

Log.d("sdcard", "block size 0 :"+Formatter.formatShortFileSize(DemoActivity.this,block0));
Log.d("sdcard", "free slot 1:"+Formatter.formatShortFileSize(DemoActivity.this,avail0));
Log.d("sdcard", "Total 2:"+ tot0 );

//myinternal sdcard path
StatFs statFs1 = new StatFs("/storage/sdcard1/");
int block1 = statFs1.getBlockSize();
int avail1 = statFs1.getAvailableBlocks() * block1;
int tot1 = statFs1.getBlockCount() *block1;

Log.d("sdcard", "block slot 4: "+Formatter.formatShortFileSize(DemoActivity.this,block1));
Log.d("sdcard", "free slot 5:"+Formatter.formatShortFileSize(DemoActivity.this,avail1));
Log.d("sdcard", "Total 6:"+Formatter.formatShortFileSize(DemoActivity.this,tot1));


my logcat :



09-16 15:28:44.501: D/sdcard(4148): block size 0 :32KB
09-16 15:28:44.501: D/sdcard(4148): free slot 1:1.4GB


09-16 15:28:44.501: D/sdcard(4148): Total 2:-705691648



09-16 15:28:44.502: D/sdcard(4148): block slot 4: 16KB
09-16 15:28:44.503: D/sdcard(4148): free slot 5:845MB
09-16 15:28:44.504: D/sdcard(4148): Total 6:1.3GB


enter image description here


0 comments:

Post a Comment