Get SDCard Megs Free : SDCard « Hardware « Android






Get SDCard Megs Free

  
//package net.bible.service.common;

import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.preference.PreferenceManager;
import android.util.Log;
//
class CommonUtils {

  private static final int DEFAULT_MAX_TEXT_LENGTH = 250;
  private static final String ELLIPSIS = "...";

  private static final String TAG = "CommonUtils";
  static private boolean isAndroid = false;

  // todo have to finish implementing switchable logging here
  static {
    try {
      if (android.os.Build.ID != null) {
        isAndroid = true;
      }
    } catch (Exception cnfe) {
      isAndroid = false;
    }
    System.out.println("isAndroid:" + isAndroid);
  }

  public static boolean isAndroid() {
    return isAndroid;
  }

  public static boolean isFroyoPlus() {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
  }

  public static long getSDCardMegsFree() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory()
        .getPath());
    long bytesAvailable = (long) stat.getBlockSize()
        * (long) stat.getAvailableBlocks();
    long megAvailable = bytesAvailable / 1048576;
    Log.d(TAG, "Megs available on SD card :" + megAvailable);
    return megAvailable;
  }

}

   
    
  








Related examples in the same category

1.Load image from mounted sdcard
2.Uri for sdcard
3.SDCard File Util
4.create File In SDCard
5.export the current database to the SDcard
6.get Sd card Path