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


Java Context.getExternalCacheDir方法代码示例

本文整理汇总了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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:ExternalCacheDiskCacheFactory.java

示例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/";
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:22,代码来源:SavorApplication.java

示例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);
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:25,代码来源:PhotoUtils.java

示例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);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:26,代码来源:ImageEditingManager.java

示例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;
}
 
开发者ID:BANKEX,项目名称:smart-asset-iot-android-demo,代码行数:15,代码来源:ImageUtils.java

示例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);
}
 
开发者ID:gavinking,项目名称:DisplayingBitmaps,代码行数:17,代码来源:ImageCache.java

示例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();
}
 
开发者ID:wutongke,项目名称:AndroidSkinAnimator,代码行数:11,代码来源:SkinFileUtils.java

示例8: clearCache

import android.content.Context; //导入方法依赖的package包/类
public static void clearCache(Context context) {
    if (context.getExternalCacheDir() != null) {
        delete(context.getExternalCacheDir());
    }

    delete(context.getCacheDir());
}
 
开发者ID:RikkaW,项目名称:Bridge,代码行数:8,代码来源:FileUtils.java

示例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;
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:17,代码来源:FileUtil.java

示例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;
    }
}
 
开发者ID:redleaf2002,项目名称:magic_imageloader_network,代码行数:16,代码来源:DiskUtils.java

示例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;
}
 
开发者ID:xiaoyaoyou1212,项目名称:XSnow,代码行数:12,代码来源:DownloadRequest.java

示例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);
}
 
开发者ID:haihaio,项目名称:AmenEye,代码行数:21,代码来源:DiskCacheManager.java

示例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();
    }
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:14,代码来源:MethodsCompat.java

示例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;
    }
 
开发者ID:Justson,项目名称:AgentWebX5,代码行数:8,代码来源:AgentWebX5Utils.java

示例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 */
    );
}
 
开发者ID:D-Cube,项目名称:Emoji-Fy,代码行数:13,代码来源:BitmapUtils.java


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