android.content.Context#getExternalCacheDir ( )源码实例Demo

下面列出了android.content.Context#getExternalCacheDir ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cube-sdk   文件: DiskFileUtils.java
/**
 * 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);
}
 
源代码2 项目: tns-core-modules-widgets   文件: Cache.java
/**
 * Get the external app cache directory.
 *
 * @param context The context to use
 * @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);
}
 
源代码3 项目: Roid-Library   文件: RLSysUtil.java
/**
 * @param context
 * @return
 */
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 {
            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;
        }
    }
}
 
源代码4 项目: Pioneer   文件: IoUtils.java
/**
 * 获得在缓存存储中的文件
 *
 * @param path
 * @return
 */
public static File fromCacheDir(Context context, String path) {
    if (path != null && path.startsWith(File.separator)) {
        path = path.substring(File.separator.length());
    }
    File cacheDir = context.getExternalCacheDir();
    File rollback = cacheDir;
    if (cacheDir != null && !ensureDirsExist(cacheDir)) {
        cacheDir = null;
    }
    if (cacheDir == null) {
        // maybe null
        cacheDir = context.getCacheDir();
    }
    if (cacheDir == null) {
        cacheDir = rollback;
    }
    if (path == null) {
        return cacheDir;
    } else {
        return new File(cacheDir, path);
    }
}
 
源代码5 项目: AudioVideoCodec   文件: FileUtils.java
/**
 * 读取缓存目录
 *
 * @param context :context
 * @return String
 */
public static String getDiskCachePath(Context context) {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        if (context.getExternalCacheDir() == null) {
            return "";
        }
        return context.getExternalCacheDir().getPath();
    } else {
        return context.getCacheDir().getPath();
    }
}
 
源代码6 项目: android-discourse   文件: Tools.java
public static File getPictureCacheDir(Context ctx) {
    File file = ctx.getExternalCacheDir();
    if (!file.exists()) {
        file.mkdirs();
    }
    return file;
}
 
源代码7 项目: starcor.xul   文件: XulSystemUtil.java
private static String getExternalCacheDir(Context context) {
    File dir = context.getExternalCacheDir();
    if (dir == null) {
        return null;
    }
    if (!dir.mkdirs() && !dir.exists()) {
        return null;
    }
    return dir.getPath();
}
 
源代码8 项目: Android-skin-support   文件: SkinFileUtils.java
private static String getCacheDir(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File cacheDir = context.getExternalCacheDir();
        if (cacheDir != null && (cacheDir.exists() || cacheDir.mkdirs())) {
            return cacheDir.getAbsolutePath();
        }
    }

    return context.getCacheDir().getAbsolutePath();
}
 
源代码9 项目: android-advanced-light   文件: OkHttpEngine.java
private OkHttpEngine(Context context) {
    File sdcache = context.getExternalCacheDir();
    int cacheSize = 10 * 1024 * 1024;
    OkHttpClient.Builder builder = new OkHttpClient.Builder()
            .connectTimeout(15, TimeUnit.SECONDS)
            .writeTimeout(20, TimeUnit.SECONDS)
            .readTimeout(20, TimeUnit.SECONDS)
            .cache(new Cache(sdcache.getAbsoluteFile(), cacheSize));
     mOkHttpClient=builder.build();
     mHandler = new Handler();
}
 
源代码10 项目: RedReader   文件: PrefsUtility.java
public static String pref_cache_location(final Context context,
		final SharedPreferences sharedPreferences) {
	File defaultCacheDir = context.getExternalCacheDir();
	if (defaultCacheDir == null) {
		defaultCacheDir = context.getCacheDir();
	}
	return getString(R.string.pref_cache_location_key,
			defaultCacheDir.getAbsolutePath(),
			context, sharedPreferences);
}
 
源代码11 项目: Theogony   文件: AndroidUtils.java
/**
 * 清空缓存 sdcard中cache目录下
 */
public static boolean clean(Context context) {
    File externalCacheDir = context.getExternalCacheDir();
    File cacheDir = context.getCacheDir();
    delete(externalCacheDir);
    delete(cacheDir);
    return true;
}
 
源代码12 项目: Android-skin-support   文件: SkinFileUtils.java
private static String getCacheDir(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File cacheDir = context.getExternalCacheDir();
        if (cacheDir != null && (cacheDir.exists() || cacheDir.mkdirs())) {
            return cacheDir.getAbsolutePath();
        }
    }

    return context.getCacheDir().getAbsolutePath();
}
 
源代码13 项目: Android-skin-support   文件: SkinFileUtils.java
private static String getCacheDir(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File cacheDir = context.getExternalCacheDir();
        if (cacheDir != null && (cacheDir.exists() || cacheDir.mkdirs())) {
            return cacheDir.getAbsolutePath();
        }
    }

    return context.getCacheDir().getAbsolutePath();
}
 
源代码14 项目: FrescoPlus   文件: DiskCacheUtil.java
public static File getDiskLruCacheDir(Context context) {
    if (context == null)
        throw new FPNullPointerException("context can not be null");
    if (!(context instanceof Application))
        context = context.getApplicationContext();
    File cacheDir = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        cacheDir = getSDFreeSize() > 100 ? context.getExternalCacheDir() : context.getCacheDir();
    } else {
        cacheDir = context.getCacheDir();
    }
    return cacheDir;
}
 
源代码15 项目: letv   文件: jm.java
public static File b(boolean z) {
    Context c = hn.a().c();
    File file = null;
    if (z && "mounted".equals(Environment.getExternalStorageState()) && (VERSION.SDK_INT >= 19 || c.checkCallingOrSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") == 0)) {
        file = c.getExternalCacheDir();
    }
    if (file == null) {
        return c.getCacheDir();
    }
    return file;
}
 
源代码16 项目: letv   文件: PatchUtils.java
private static File getPatchDownloadPatchDir(Context context) {
    File patch = context.getExternalCacheDir();
    if (patch == null || !patch.exists()) {
        return context.getCacheDir();
    }
    return patch;
}
 
源代码17 项目: CrazyDaily   文件: FileUtil.java
@SuppressWarnings("ResultOfMethodCallIgnored")
public static File getWebCacheFile(Context context) {
    if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        return null;
    }
    File file = new File(context.getExternalCacheDir(), CacheConstant.CACHE_DIR_WEB);
    if (!file.exists()) {
        file.mkdirs();
    }
    return file;
}
 
源代码18 项目: OpenMapKitAndroid   文件: MapTileCache.java
/**
 * Creates a unique subdirectory of the designated app cache directory. Tries to use external
 * but if not mounted, falls back on internal storage.
 */
public static File getDiskCacheDir(Context context, String uniqueName) {
    // Check if media is mounted or storage is built-in, if so, try and use external cache dir
    // otherwise use internal cache dir
    final String cachePath =
            context.getExternalCacheDir() != null && (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
                    || (!Environment.isExternalStorageRemovable()))
                    ? context.getExternalCacheDir().getPath()
                    : context.getCacheDir().getPath();
    Log.i(TAG, "cachePath: '" + cachePath + "'");

    return new File(cachePath, uniqueName);
}
 
源代码19 项目: ImagePicker   文件: MediaUtils.java
private static String generateTempFilepath(Context context) {
    // 保存到app的cache文件夹下
    return context.getExternalCacheDir() + File.separator + "image_picker_image_uri.jpg";
}
 
源代码20 项目: bcm-android   文件: PersistentBlobProvider.java
private static @NonNull
File getExternalDir(Context context) throws IOException {
    final File externalDir = context.getExternalCacheDir();
    if (externalDir == null) throw new IOException("no external files directory");
    return externalDir;
}
 
 方法所在类
 同类方法