package com.fmy.state;
import java.text.Format;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.text.format.Formatter;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void lick(View v) {
StatFs state = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
long free;
if (Build.VERSION.SDK_INT>=18){
free = state.getFreeBytes();
}else{
free = state.getFreeBlocks()*state.getBlockSize();
}
String formatFileSize = Formatter.formatFileSize(this, free);
Toast.makeText(this, formatFileSize, 0).show();
}
}