List of usage examples for android.content Context getExternalCacheDir
@Nullable public abstract File getExternalCacheDir();
From source file:Main.java
private static File getExternalCacheDir(Context context) { if (hasExternalCacheDir()) { return context.getExternalCacheDir(); }// w w w . j a v a 2 s .c om final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir); }
From source file:Main.java
public static String getCachePath(final Context context) { if (true)//from w ww. j a v a 2 s . c o m return "/sdcard/"; if (context.getExternalCacheDir() != null) { return context.getExternalCacheDir() + "/"; } else { return context.getCacheDir().getAbsolutePath() + "/"; } }
From source file:Main.java
/** * Get the external app cache directory. * /*from w w w .ja v a 2s. com*/ * @param context * The context to use * @return The external cache dir */ public static File getExternalCacheDir(Context context) { if (hasExternalCacheDir()) { return context.getExternalCacheDir(); } // Before Froyo we need to construct the external cache dir ourselves final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir); }
From source file:Main.java
public static void saveJPGE_After(Context context, Bitmap bitmap, String path) { File file = new File(context.getExternalCacheDir() + path); try {/*ww w .ja v a2s. com*/ FileOutputStream out = new FileOutputStream(file); if (bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)) { out.flush(); out.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Get a usable cache directory (external if available, internal otherwise) * * @param context The {@link android.content.Context} to use * @param uniqueName A unique directory name to append to the cache * directory//from w w w .j a v a2 s .c o m * @return The cache directory */ public static File getCacheDir(final Context context, final String uniqueName) { File cachePath = context.getExternalCacheDir(); if (cachePath == null || !cachePath.canWrite()) { cachePath = context.getCacheDir(); } File cacheDir = new File(cachePath, uniqueName); if (!cacheDir.exists()) { cacheDir.mkdirs(); } if (!cacheDir.canWrite()) { cacheDir.setWritable(true); } return cacheDir; }
From source file:Main.java
/** * Get APNG working directory/* w ww . j ava 2s .co m*/ * @param context Application Context * @return Reference to the working directory */ public static File getWorkingDir(Context context) { File workingDir = null; File cacheDir = context.getExternalCacheDir(); if (cacheDir == null) { cacheDir = context.getCacheDir(); } if (cacheDir != null) { workingDir = new File(String.format("%s/apng/.nomedia/", cacheDir.getPath())); if (!workingDir.exists()) { workingDir.mkdirs(); } } return workingDir; }
From source file:Main.java
/** * Get ideal cache directory based on available * * @return Ideal file location for caching *///w w w . j a v a 2 s .c om public static File getIdealCacheDirectory(Context context) { File externalCacheDir = context.getExternalCacheDir(); if (getTotalExternalMemorySize() < getTotalInternalMemorySize() || externalCacheDir == null) { return context.getCacheDir(); } return externalCacheDir; }
From source file:Main.java
/** * Get the external app cache directory. * * @param context The context to use/*from ww w .j a va2s. c o m*/ * * @return The external cache dir */ public static File getExternalCacheDir(Context context) { if (hasExternalCacheDir()) { return context.getExternalCacheDir(); } // Before Froyo we need to construct the external cache dir ourselves final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir); }
From source file:Main.java
/** * Get the external app cache directory. * * @param context The context to use/*from w w w . j a v a 2 s. c o m*/ * @return The external cache dir */ @SuppressLint("NewApi") public static File getExternalCacheDir(Context context) { if (hasExternalCacheDir()) { return context.getExternalCacheDir(); } // Before Froyo we need to construct the external cache dir ourselves final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir); }
From source file:Main.java
public static boolean isSDCardAvailable(final Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { if (context.getExternalCacheDir() != null) { return true; }//from w w w .j av a 2 s .com } return false; }