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