当前位置: 首页>>代码示例>>Java>>正文


Java Context.getCacheDir方法代码示例

本文整理汇总了Java中android.content.Context.getCacheDir方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getCacheDir方法的具体用法?Java Context.getCacheDir怎么用?Java Context.getCacheDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.getCacheDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import android.content.Context; //导入方法依赖的package包/类
/**
 * Initialize HeifReader module.
 *
 * @param context Context.
 */
public static void initialize(Context context) {
    mRenderScript = RenderScript.create(context);
    mCacheDir = context.getCacheDir();

    // find best HEVC decoder
    mDecoderName = null;
    mDecoderSupportedSize = new Size(0, 0);
    int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (codecInfo.isEncoder()) {
            continue;
        }
        for (String type : codecInfo.getSupportedTypes()) {
            if (type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
                MediaCodecInfo.CodecCapabilities cap = codecInfo.getCapabilitiesForType(MediaFormat.MIMETYPE_VIDEO_HEVC);
                MediaCodecInfo.VideoCapabilities vcap = cap.getVideoCapabilities();
                Size supportedSize = new Size(vcap.getSupportedWidths().getUpper(), vcap.getSupportedHeights().getUpper());
                Log.d(TAG, "HEVC decoder=\"" + codecInfo.getName() + "\""
                        + " supported-size=" + supportedSize
                        + " color-formats=" + Arrays.toString(cap.colorFormats)
                );
                if (mDecoderSupportedSize.getWidth() * mDecoderSupportedSize.getHeight() < supportedSize.getWidth() * supportedSize.getHeight()) {
                    mDecoderName = codecInfo.getName();
                    mDecoderSupportedSize = supportedSize;
                }
            }
        }
    }
    if (mDecoderName == null) {
        throw new RuntimeException("no HEVC decoding support");
    }
    Log.i(TAG, "HEVC decoder=\"" + mDecoderName + "\" supported-size=" + mDecoderSupportedSize);
}
 
开发者ID:yohhoy,项目名称:heifreader,代码行数:40,代码来源:HeifReader.java

示例2: getPhotoCacheDir

import android.content.Context; //导入方法依赖的package包/类
public static File getPhotoCacheDir(Context context, File file) {
    File cacheDir = context.getCacheDir();
    if (cacheDir != null) {
        File mCacheDir = new File(cacheDir,DEFAULT_DISK_CACHE_DIR);
        if (!mCacheDir.mkdirs() && (!mCacheDir.exists() || !mCacheDir.isDirectory())) {
            return file;
        }else {
            return new File(mCacheDir, file.getName());
        }
    }
    if (Log.isLoggable(TAG, Log.ERROR)) {
        Log.e(TAG, "default disk cache dir is null");
    }
    return file;
}
 
开发者ID:duckitgo,项目名称:DigPhotoPicker,代码行数:16,代码来源:TFileUtils.java

示例3: createTempFile

import android.content.Context; //导入方法依赖的package包/类
/**
 * Create a temporary file in the cache directory on either internal or external storage,
 * whichever is available and has more free space.
 *
 * @param mimeType the MIME type of the file to create (image/*)
 */
private static File createTempFile(Context context, @Nullable String mimeType)
    throws IOException {
  File externalCacheDir = context.getExternalCacheDir();
  File internalCacheDir = context.getCacheDir();
  File cacheDir;
  if (externalCacheDir == null && internalCacheDir == null) {
    throw new IOException("No cache directory available");
  }
  if (externalCacheDir == null) {
    cacheDir = internalCacheDir;
  }
  else if (internalCacheDir == null) {
    cacheDir = externalCacheDir;
  } else {
    cacheDir = externalCacheDir.getFreeSpace() > internalCacheDir.getFreeSpace() ?
        externalCacheDir : internalCacheDir;
  }
  return File.createTempFile(TEMP_FILE_PREFIX, getFileExtensionForType(mimeType), cacheDir);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:26,代码来源:ImageEditingManager.java

示例4: getDestinationDirectory

import android.content.Context; //导入方法依赖的package包/类
private static File getDestinationDirectory(Context context, int destination, boolean running)
        throws IOException {
    switch (destination) {
        case Downloads.Impl.DESTINATION_CACHE_PARTITION:
        case Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE:
        case Downloads.Impl.DESTINATION_CACHE_PARTITION_NOROAMING:
            if (running) {
                return context.getFilesDir();
            } else {
                return context.getCacheDir();
            }
        case Downloads.Impl.DESTINATION_EXTERNAL:
            final File target = new File(
                    Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS);
            if (!target.isDirectory() && target.mkdirs()) {
                throw new IOException("unable to create external downloads directory");
            }
            return target;

        default:
            throw new IllegalStateException("unexpected destination: " + destination);
    }
}
 
开发者ID:limpoxe,项目名称:Android-DownloadManager,代码行数:24,代码来源:Helpers.java

示例5: getPhotoCacheDir

import android.content.Context; //导入方法依赖的package包/类
/**
 * Returns a directory with the given name in the private cache directory of the application to
 * use to store retrieved media and thumbnails.
 *
 * @param context   A context.
 * @param cacheName The name of the subdirectory in which to store the cache.
 * @see #getPhotoCacheDir(android.content.Context)
 */
@Nullable
public static File getPhotoCacheDir(Context context, String cacheName) {
  File cacheDir = context.getCacheDir();
  if (cacheDir != null) {
    File result = new File(cacheDir, cacheName);
    if (!result.mkdirs() && (!result.exists() || !result.isDirectory())) {
      // File wasn't able to create a directory, or the result exists but not a directory
      return null;
    }
    return result;
  }
  if (Log.isLoggable(TAG, Log.ERROR)) {
    Log.e(TAG, "default disk cache dir is null");
  }
  return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:Glide.java

示例6: getCacheDir

import android.content.Context; //导入方法依赖的package包/类
/**
 * 获取缓存路径
 *
 * @param context
 * @return 返回缓存文件路径
 */
public static File getCacheDir(Context context) {
    File cache;
    if (hasExternalStorage()) {
        cache = context.getExternalCacheDir();
    } else {
        cache = context.getCacheDir();
    }
    if (!cache.exists())
        cache.mkdirs();
    return cache;
}
 
开发者ID:zyj1609wz,项目名称:Dynamic,代码行数:18,代码来源:FileUtils.java

示例7: getPatchDownloadPatchDir

import android.content.Context; //导入方法依赖的package包/类
private static File getPatchDownloadPatchDir(Context context) {
    File patch = context.getExternalCacheDir();
    if (patch == null || !patch.exists()) {
        return context.getCacheDir();
    }
    return patch;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:8,代码来源:PatchUtils.java

示例8: getCacheFile

import android.content.Context; //导入方法依赖的package包/类
public static File getCacheFile(Context context, String filename) {
    if (context.getExternalCacheDir() != null) {
        return new File(context.getExternalCacheDir(), filename);
    } else {
        return new File(context.getCacheDir(), filename);
    }
}
 
开发者ID:RikkaW,项目名称:Bridge,代码行数:8,代码来源:FileUtils.java

示例9: newDownloadDir

import android.content.Context; //导入方法依赖的package包/类
/**
 * @param context ApplicationContext
 *
 * @return 一个下载的最终目录,{@link AbsDownloadDir}是一个带有自定义规则的下载目录(如:目录是否会自动清理,目录下的文件命名规范等)
 */
@Override
public AbsDownloadDir newDownloadDir(Context context) {
	if (SdCardUtils.isSdCardHaveEnoughSpace(context, MAX_LIMIT_MB)) {
		return new DefaultDownloadDir(SdCardUtils.getSdcardRootPath() + "/Android/data/.cache/.apk",
				MAX_LIMIT_MB,
				MAX_LIMIT_TIME
		);
	} else {
		return new DefaultDownloadDir(context.getCacheDir() + "/.apk", MAX_LIMIT_MB, MAX_LIMIT_TIME);
	}
}
 
开发者ID:youmi,项目名称:nativead,代码行数:17,代码来源:BaseApkFileDownloadManager.java

示例10: retrieveCacheDir

import android.content.Context; //导入方法依赖的package包/类
private void retrieveCacheDir(final Context context) {
	final String tag="retrieveCacheDir - ";
	dirCache = null;
	if (isExternalStorageWritable()){
		final File dir=new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES),DIRECTORY_TILES_CACHE);
		if (!dir.exists()) {
			try {
				if (!dir.mkdirs()){
					Log.w(TAG,tag+"Not possible to create directory: "+ dir.getPath());
				} else {
					dirCache=dir;
				}
			} catch (SecurityException e){
				Log.w(TAG,tag+"Not possible to create directory: "+ dir.getPath(),e);
			}
		} else if (dir.getFreeSpace()<MIN_FREE_BYTES){
			Log.w(TAG,tag+"Not enough free space on external files dir. Minimal required: "+MIN_FREE_BYTES+" bytes.");
		} else {
			dirCache=dir;
		}
	}

	if (dirCache==null){
		Log.w(TAG,tag+"No external files directory available, use cache directory.");
		dirCache = context.getCacheDir();
	}
}
 
开发者ID:videgro,项目名称:Ships,代码行数:28,代码来源:HttpCacheTileServer.java

示例11: trimCache

import android.content.Context; //导入方法依赖的package包/类
public static void trimCache(Context context) {
	try {
		File dir = context.getCacheDir();

		if (dir != null && dir.isDirectory()) {
			deleteDir(dir);
		}
	} catch (Exception ignored) {

	}
}
 
开发者ID:Louis19910615,项目名称:youkes_browser,代码行数:12,代码来源:Utils.java

示例12: getCecheFolder

import android.content.Context; //导入方法依赖的package包/类
/**
 * 获取的目录默认没有最后的”/”,需要自己加上
 * 获取本应用图片缓存目录
 *
 * @return
 */
public static File getCecheFolder(Context context) {
    File folder = new File(context.getCacheDir(), "IMAGE_CACHE");
    if (!folder.exists()) {
        folder.mkdir();
    }
    return folder;
}
 
开发者ID:ChunweiDu,项目名称:Utils,代码行数:14,代码来源:FileUtil.java

示例13: checkCacheParentDirectory

import android.content.Context; //导入方法依赖的package包/类
private File checkCacheParentDirectory(Context context){
    File cacheFileDir = new File(context.getCacheDir(),KEY_CACHE_DIRECTORY);
    if(!cacheFileDir.exists()){
        if(cacheFileDir.mkdirs()){
            return cacheFileDir;
        }
    }else{
        return cacheFileDir;
    }
    return null;
}
 
开发者ID:Pingsh,项目名称:Mix,代码行数:12,代码来源:FileManager.java

示例14: getCacheDirectory

import android.content.Context; //导入方法依赖的package包/类
public static File getCacheDirectory(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) && context.getExternalCacheDir() != null) {
        return context.getExternalCacheDir();
    }
    return context.getCacheDir();
}
 
开发者ID:ccrama,项目名称:Slide-RSS,代码行数:7,代码来源:ImageLoaderUtils.java

示例15: getWhenLastCached

import android.content.Context; //导入方法依赖的package包/类
/**
 * Checks when were the updates cached last time.
 * @param ctx Used to get cache directory
 * @return {@link java.util.Date} object of when it happened
 */
public static Date getWhenLastCached(Context ctx) {
    File appDir = ctx.getCacheDir();
    File lastSynced = new File(appDir, "update.json");
    return new Date(lastSynced.lastModified());
}
 
开发者ID:kfaryarok,项目名称:kfaryarok-android,代码行数:11,代码来源:UpdateHelper.java


注:本文中的android.content.Context.getCacheDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。