List of usage examples for android.content Context getExternalCacheDir
@Nullable public abstract File getExternalCacheDir();
From source file:Main.java
/** * Creates a media file in the {@code Environment.DIRECTORY_PICTURES} directory. The directory * is persistent and available to other applications like gallery. * * @param type Media type. Can be video or image. * @return A file object pointing to the newly created file. *///from www .j a v a 2 s.com public static File getTempOutputMediaFile(Context context, int type) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { return null; } @SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); if (type == MEDIA_TYPE_IMAGE) { timeStamp += ".jpg"; } else if (type == MEDIA_TYPE_VIDEO) { timeStamp += ".mp4"; } else { return null; } try { return new File(context.getExternalCacheDir().getAbsolutePath(), timeStamp); } catch (NullPointerException e) { e.printStackTrace(); return null; } }
From source file:org.nativescript.widgets.image.Cache.java
/** * Get the external app cache directory. * * @param context The context to use//from w w w. ja v a 2 s .co m * @return The external cache dir */ @TargetApi(VERSION_CODES.FROYO) public static File getExternalCacheDir(Context context) { if (Utils.hasFroyo()) { if (Utils.hasKitKat() || context.checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, android.os.Process.myPid(), android.os.Process.myUid()) == PackageManager.PERMISSION_GRANTED) { return context.getExternalCacheDir(); } return null; } // 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:com.zz.lib.bitmapfun.util.ImageCache.java
/** * Get the external app cache directory. * * @param context The context to use/*from w ww .j a v a 2 s . co m*/ * @return The external cache dir */ @TargetApi(8) public static File getExternalCacheDir(Context context) { if (Utils.hasFroyo()) { File ret = context.getExternalCacheDir(); if (ret != null) return ret; } if (getUsableSpace(Environment.getExternalStorageDirectory()) < 1024 * 100) { //! SD?? return context.getCacheDir(); } // 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:com.qingzhou.app.image.util.ImageCache.java
/** * Get the external app cache directory. * * @param context The context to use// ww w .ja v a2s . co m * @return The external cache dir */ @TargetApi(8) public static File getExternalCacheDir(Context context) { if (Utils.hasFroyo()) { return context.getExternalCacheDir(); } // Before Froyo we need to construct the external cache dir ourselves //final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; final String cacheDir = Constants.CACHE_DIR; //return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir); return new File(cacheDir); }
From source file:org.catnut.util.CatnutUtils.java
public static String mkdir(Context context, String location) throws Exception { // ???sk?...//from ww w .j a v a2 s . com File dir = new File(context.getExternalCacheDir().getPath() + File.separator + location); if (!dir.exists() && !dir.mkdirs()) { throw new RuntimeException(context.getString(R.string.cannot_create_dir)); } return dir.getPath(); }
From source file:com.eamonndunne.londontraffic.view.ImageCache.java
/** * Get the external app cache directory. * * @param context The context to use/* w w w .java 2 s. c o m*/ * @return The external cache dir */ @TargetApi(VERSION_CODES.FROYO) public static File getExternalCacheDir(Context context) { if (Utils.hasFroyo()) { return context.getExternalCacheDir(); } final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/"; return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir); }
From source file:com.universal.framwork.bitmapfun.ImageCache.java
/** * Get the external app cache directory. * * @param context The context to use/*from w ww.j a va 2 s . c o m*/ * @return The external cache dir */ @TargetApi(8) public static File getExternalCacheDir(Context context) { if (Utils.hasFroyo()) { LogUtil.d("yzy", "hasFroyo is true return path is -->" + context.getExternalCacheDir()); return context.getExternalCacheDir(); } LogUtil.d("yzy", "hasFroyo is false return path is -->" + "/Android/data/" + context.getPackageName() + "/cache/"); // 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:prince.app.sphotos.util.ImageCache.java
/** * Get the external app cache directory. * * @param context The context to use//w w w . ja v a 2 s . com * @return The external cache dir */ @TargetApi(VERSION_CODES.FROYO) public static File getExternalCacheDir(Context context) { if (Global.hasFroyo()) { 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:android.bitmap.util.ImageCache.java
/** * Get the external app cache directory. * * @param context The context to use//from w w w . j av a2s. c o m * @return The external cache dir */ @TargetApi(VERSION_CODES.FROYO) public static File getExternalCacheDir(Context context) { if (Utils.hasFroyo()) { 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:com.rp.justcast.photos.ImageCache.java
/** * Get the external app cache directory. * * @param context The context to use/*from w w w .j a v a2 s. c o m*/ * @return The external cache dir */ @TargetApi(VERSION_CODES.FROYO) public static File getExternalCacheDir(Context context) { if (JustCastUtils.hasFroyo()) { 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); }