本文整理汇总了Java中android.content.Context.getExternalCacheDir方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getExternalCacheDir方法的具体用法?Java Context.getExternalCacheDir怎么用?Java Context.getExternalCacheDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.getExternalCacheDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ExternalCacheDiskCacheFactory
import android.content.Context; //导入方法依赖的package包/类
public ExternalCacheDiskCacheFactory(final Context context, final String diskCacheName,
int diskCacheSize) {
super(new CacheDirectoryGetter() {
@Override
public File getCacheDirectory() {
File cacheDirectory = context.getExternalCacheDir();
if (cacheDirectory == null) {
return null;
}
if (diskCacheName != null) {
return new File(cacheDirectory, diskCacheName);
}
return cacheDirectory;
}
}, diskCacheSize);
}
示例2: initCacheFile
import android.content.Context; //导入方法依赖的package包/类
private void initCacheFile(Context context) {
String cachePath = AppUtils.getSDCardPath()+"savor"+File.separator;
mListCachePath = cachePath+"cache";
mSplashCachePath = cachePath+"splash";
mSplashTempPath = cachePath+"temp";
mLogFilePath = cachePath + "log";
mLogTempFilePath = cachePath + "log"+File.separator+"temp";
mLottoryNumDir = cachePath+"lottery"+File.separator+"num";
mLottoryRandomDir = cachePath+"lottery"+File.separator+"random";
mLottoryCountDir = cachePath+"lottery"+File.separator+"count";
File externalCacheDir = context.getExternalCacheDir();
File fileDir = context.getFilesDir();
VodTypePath = externalCacheDir + File.separator + ".VodTypeFile";
VodStorePath = fileDir + File.separator + ".VodStoreFile";
ImageCachePath = externalCacheDir + File.separator + ".ImageCacheFile";
ImageSplash = ImageCachePath + File.separator + ".bg_splash.png";
GalleyPath = ImageCachePath + "/galley";
PdfJsPath = externalCacheDir + File.separator;
OfficePath = fileDir + File.separator + "documents/";
}
示例3: openCamera
import android.content.Context; //导入方法依赖的package包/类
/**
* 打开系统相机
* @param context
* @param fileName
*/
public static void openCamera(Context context, String fileName) {
String status = Environment.getExternalStorageState();
if (!Environment.MEDIA_MOUNTED.equals(status)) {
Toast.makeText(context, "SD卡不可以", Toast.LENGTH_LONG).show();
return;
}
File mCurrentPhotoFile = new File(context.getExternalCacheDir(), fileName);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri imageUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // 7.0使用FileProvider
imageUri = FileProvider.getUriForFile(context, "com.highway.study.provider", mCurrentPhotoFile);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
imageUri = Uri.fromFile(mCurrentPhotoFile);
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, MAX_PHOTO_SIZE);
((Activity)context).startActivityForResult(intent, CAMERA_WITH_DATA);
}
示例4: 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);
}
示例5: createImageFile
import android.content.Context; //导入方法依赖的package包/类
public File createImageFile(Context context) throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = new File(context.getExternalCacheDir() + "/photos");
if (!storageDir.exists()) {
boolean success = storageDir.mkdir();
Timber.d("Success " + success);
}
File image = File.createTempFile(imageFileName, ".jpg", storageDir);
// Save a file: path for use with ACTION_VIEW intents
insertPath(image.getAbsolutePath());
return image;
}
示例6: getExternalCacheDir
import android.content.Context; //导入方法依赖的package包/类
/**
* 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()) {
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);
}
示例7: getCacheDir
import android.content.Context; //导入方法依赖的package包/类
public 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();
}
示例8: clearCache
import android.content.Context; //导入方法依赖的package包/类
public static void clearCache(Context context) {
if (context.getExternalCacheDir() != null) {
delete(context.getExternalCacheDir());
}
delete(context.getCacheDir());
}
示例9: getCacheDir
import android.content.Context; //导入方法依赖的package包/类
/**
* 获取缓存文件夹
*
* @param context 上下文
* @param dirName 文件夹名称
* @return 缓存文件夹
*/
@Nullable
public static File getCacheDir(@NonNull Context context, @NonNull String dirName) {
File rootDir = context.getExternalCacheDir();
File cacheFile = new File(rootDir, dirName);
if (!cacheFile.exists()) {
cacheFile.mkdir();
}
return cacheFile;
}
示例10: getDiskCacheDir
import android.content.Context; //导入方法依赖的package包/类
public static String getDiskCacheDir(Context context) {
File cacheFile = null;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable()) {
cacheFile = context.getExternalCacheDir();
} else {
cacheFile = context.getCacheDir();
}
if (cacheFile != null) {
return cacheFile.getPath();
} else {
String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/";
return Environment.getExternalStorageDirectory().getPath() + cacheDir;
}
}
示例11: getDiskCachePath
import android.content.Context; //导入方法依赖的package包/类
private String getDiskCachePath(Context context) {
String cachePath;
if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable())
&& context.getExternalCacheDir() != null) {
cachePath = context.getExternalCacheDir().getPath();
} else {
cachePath = context.getCacheDir().getPath();
}
return cachePath;
}
示例12: getCacheFile
import android.content.Context; //导入方法依赖的package包/类
/**
* 获取缓存的路径 两个路径在卸载程序时都会删除,因此不会在卸载后还保留乱七八糟的缓存
* 有SD卡时获取 /sdcard/Android/data/<application package>/cache
* 无SD卡时获取 /data/data/<application package>/cache
*
* @param context 上下文
* @param uniqueName 缓存目录下的细分目录,用于存放不同类型的缓存
* @return 缓存目录 File
*/
private File getCacheFile(Context context, String uniqueName) {
String cachePath = null;
if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable())
&& context.getExternalCacheDir() != null) {
cachePath = context.getExternalCacheDir().getPath();
} else {
cachePath = context.getCacheDir().getPath();
}
return new File(cachePath + File.separator + uniqueName);
}
示例13: getExternalCacheDir
import android.content.Context; //导入方法依赖的package包/类
@TargetApi(8)
public static File getExternalCacheDir(Context context) {
// // return context.getExternalCacheDir(); API level 8
//
// // e.g. "<sdcard>/Android/data/<package_name>/cache/"
// final File extCacheDir = new File(Environment.getExternalStorageDirectory(),
// "/Android/data/" + context.getApplicationInfo().packageName + "/cache/");
// extCacheDir.mkdirs();
// return extCacheDir;
return context.getExternalCacheDir();
}
示例14: getDiskExternalCacheDir
import android.content.Context; //导入方法依赖的package包/类
static String getDiskExternalCacheDir(Context context) {
File mFile = context.getExternalCacheDir();
if (Environment.MEDIA_MOUNTED.equals(EnvironmentCompat.getStorageState(mFile)))
return mFile.getAbsolutePath();
return null;
}
示例15: createTempImageFile
import android.content.Context; //导入方法依赖的package包/类
static File createTempImageFile(Context context) throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = context.getExternalCacheDir();
return File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
}