本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例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) {
}
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}