Example #1
0
  /**
   * Get the external application cache directory.
   *
   * @param context The context to use
   * @return The external cache folder : /storage/sdcard0/Android/data/com.srain.sdk/cache
   */
  @TargetApi(Build.VERSION_CODES.FROYO)
  public static File getExternalCacheDir(Context context) {
    if (Version.hasFroyo()) {
      File path = context.getExternalCacheDir();

      // In some case, even the sd card is mounted, getExternalCacheDir will return null, may be it
      // is nearly full.
      if (path != null) {
        return path;
      }
    }

    // Before Froyo or the path is null, we need to construct the external cache folder ourselves
    final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/";
    return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
  }
Example #2
0
 /**
  * @param path
  * @return -1 means path is null, 0 means path is not exist.
  */
 @SuppressWarnings("deprecation")
 @TargetApi(Build.VERSION_CODES.GINGERBREAD)
 public static long getTotalSpace(File path) {
   if (path == null) {
     return -1;
   }
   if (Version.hasGingerbread()) {
     return path.getTotalSpace();
   } else {
     if (!path.exists()) {
       return 0;
     } else {
       final StatFs stats = new StatFs(path.getPath());
       return (long) stats.getBlockSize() * (long) stats.getBlockCount();
     }
   }
 }