當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。