本文整理匯總了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());
}