List of usage examples for android.content Context getExternalCacheDir
@Nullable public abstract File getExternalCacheDir();
From source file:Main.java
public static final File getDownloadDir(Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return new File(context.getExternalCacheDir(), DOWNLOAD_DIR); }// ww w. ja v a2 s. com return new File(context.getCacheDir(), DOWNLOAD_DIR); }
From source file:Main.java
/** * Get the external app cache directory. * * @param context The context to use// ww w . j a va2s.com * @return The external cache dir */ @TargetApi(Build.VERSION_CODES.FROYO) private static File getExternalCacheDir(Context context) { File f; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { f = context.getExternalCacheDir(); if (f != null) { return f; } } // Before Froyo we need to construct the external cache dir ourselves final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; f = new File(Environment.getExternalStorageDirectory().getPath() + cacheDir); return f; }
From source file:Main.java
public static String getExternalCacheDir(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { File f1 = context.getExternalCacheDir(); if (f1 != null) { return f1.getPath(); } else {//from ww w . j ava 2 s. c o m return null; } } else { final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; File f2 = Environment.getExternalStorageDirectory(); if (f2 != null) { return f2.getPath() + cacheDir; } else { return null; } } }
From source file:Main.java
public static void cleanExternalCache(Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { deleteFilesByDirectory(context.getExternalCacheDir()); }/*w w w . j a v a 2s.co m*/ }
From source file:org.iota.wallet.helper.Utils.java
public static File getExternalIotaDirectory(Context context) { try {//from www. j a v a 2 s .c om File cacheDir = new File(context.getExternalCacheDir(), "iota"); if (!cacheDir.exists()) { cacheDir.mkdirs(); } return cacheDir; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String dstPath(Context context) { String cachePath;/*from www.java 2 s . c o m*/ if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { cachePath = context.getExternalCacheDir().getPath(); } else { cachePath = context.getCacheDir().getPath(); } return cachePath; }
From source file:Main.java
public static String getDiskCacheDir(Context context, String dirName) { final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ? context.getExternalCacheDir().getPath() : context.getCacheDir().getPath(); return cachePath + File.separator + dirName; }
From source file:Main.java
/** * Creates temporary file in external storage, or in case when extrnal storage is not available * temporary file is created in the internal storage. * @param context - Context/*from w ww . j a v a 2 s. com*/ * @return instance of java.io.File or null if error occured. */ public static File createTempFile(Context context) { if (context == null) throw new IllegalArgumentException(); File saveToDir = context.getExternalCacheDir(); if (saveToDir == null) { saveToDir = context.getCacheDir(); } File tempFile = null; try { tempFile = File.createTempFile("parrot", "", saveToDir); } catch (IOException e) { e.printStackTrace(); return null; } return tempFile; }
From source file:Main.java
public static String getCacheDir(Context ctx) { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable() ? ctx.getExternalCacheDir().getPath() : ctx.getCacheDir().getPath(); }
From source file:Main.java
private static File getExternalCacheDir(Context context) { File path = null;//from w ww . j a va 2s . c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { path = context.getExternalCacheDir(); // In some case, even the sd card is mounted, // getExternalCacheDir will return null // may be it is nearly full. } if (null == 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/"; path = new File(Environment.getExternalStorageDirectory().getPath() + cacheDir); } return path; }