android.app.Application#getCacheDir ( )源码实例Demo

下面列出了android.app.Application#getCacheDir ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Android-utils   文件: CrashHelper.java
/**
 * Init crash log cache directory.
 *
 * @param application application
 * @param crashDirPath crash log file cache directory
 */
private static void initCacheDir(Application application, final String crashDirPath) {
    if (StringUtils.isSpace(crashDirPath)) {
        dir = null;
    } else {
        dir = crashDirPath.endsWith(FILE_SEP) ? crashDirPath : crashDirPath + FILE_SEP;
    }
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            && application.getExternalCacheDir() != null) {
        // defaultDir: /android/data/< package name >/cache/crash/...
        defaultDir = application.getExternalCacheDir() + FILE_SEP + "crash" + FILE_SEP;
    } else {
        // defaultDir: /data/data/< package name >/cache/crash/...
        defaultDir = application.getCacheDir() + FILE_SEP + "crash" + FILE_SEP;
    }
}
 
源代码2 项目: Dagger2-Sample   文件: ApiModule.java
@Provides
@Singleton
Cache provideCache(Application application) {
    long cacheSize = 10 * 1024 * 1024; // 10 MB
     File httpCacheDirectory = new File(application.getCacheDir(), "http-cache");
    return new Cache(httpCacheDirectory, cacheSize);
}
 
源代码3 项目: Pioneer   文件: DataModule.java
static OkHttpClient createOkHttpClient(Application app) {
    OkHttpClient client = new OkHttpClient();

    // Install an HTTP cache in the application cache directory.
    File cacheDir = new File(app.getCacheDir(), "http");
    Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);
    client.setCache(cache);

    return client;
}
 
源代码4 项目: Xndroid   文件: BaseSuggestionsModel.java
BaseSuggestionsModel(@NonNull Application application, @NonNull String encoding) {
    mEncoding = encoding;
    mLanguage = getLanguage();
    File suggestionsCache = new File(application.getCacheDir(), "suggestion_responses");
    mHttpClient = new OkHttpClient.Builder()
        .cache(new Cache(suggestionsCache, FileUtils.megabytesToBytes(1)))
        .addNetworkInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR)
        .build();
    mCacheControl = new CacheControl.Builder().maxStale(1, TimeUnit.DAYS).build();
}
 
源代码5 项目: u2020-mvp   文件: DataModule.java
static OkHttpClient.Builder createOkHttpClient(Application app) {
    // Install an HTTP cache in the application cache directory.
    File cacheDir = new File(app.getCacheDir(), "http");
    Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);
    return new OkHttpClient.Builder()
            .connectTimeout(10, TimeUnit.SECONDS)
            .readTimeout(10, TimeUnit.SECONDS)
            .writeTimeout(10, TimeUnit.SECONDS)
            .cache(cache);

}
 
源代码6 项目: Learning-Resources   文件: OkClientFactory.java
@NonNull
public static OkHttpClient provideOkHttpClient(Application app) {
    // Install an HTTP cache in the application cache directory.
    File cacheDir = new File(app.getCacheDir(), "http");
    Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);

    OkHttpClient.Builder builder = new OkHttpClient.Builder()
            .cache(cache);
    if (BuildConfig.DEBUG) {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.interceptors().add(loggingInterceptor);
    }
    return builder.build();
}
 
源代码7 项目: Learning-Resources   文件: OkClientFactory.java
@NonNull
public static OkHttpClient provideOkHttpClient(Application app) {
    // Install an HTTP cache in the application cache directory.
    File cacheDir = new File(app.getCacheDir(), "http");
    Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);

    OkHttpClient.Builder builder = new OkHttpClient.Builder()
            .cache(cache);
    if (BuildConfig.DEBUG) {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.interceptors().add(loggingInterceptor);
    }
    return builder.build();
}
 
源代码8 项目: u2020   文件: DataModule.java
static OkHttpClient.Builder createOkHttpClient(Application app) {
  // Install an HTTP cache in the application cache directory.
  File cacheDir = new File(app.getCacheDir(), "http");
  Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);

  return new OkHttpClient.Builder()
      .cache(cache);
}
 
源代码9 项目: dagger2-example   文件: DataModule.java
public static OkHttpClient createOkHttpClient(Application app) {
    OkHttpClient client = new OkHttpClient();
    // Install an HTTP cache in the application cache directory.
    try {
        File cacheDir = new File(app.getCacheDir(), "http");

        Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);
        client.setCache(cache);
    } catch(IOException e) {
        Log.e("DatModule", "Unable to install disk cache.", e);
    }

    return client;
}
 
源代码10 项目: Pioneer   文件: DataModule.java
static OkHttpClient createOkHttpClient(Application app) {
    OkHttpClient client = new OkHttpClient();

    // Install an HTTP cache in the application cache directory.
    File cacheDir = new File(app.getCacheDir(), "http");
    Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);
    client.setCache(cache);

    return client;
}
 
源代码11 项目: DebugDrawer   文件: MainActivity.java
private static OkHttpClient.Builder createOkHttpClientBuilder(Application app) {
    // Install an HTTP cache in the application cache directory.
    File cacheDir = new File(app.getCacheDir(), "okhttp3-cache");
    Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);

    return new OkHttpClient.Builder()
        .cache(cache)
        .addInterceptor(LogsModule.chuckInterceptor(app))
        .addInterceptor(NetworkQualityModule.interceptor(app))
        .readTimeout(10, TimeUnit.SECONDS)
        .writeTimeout(10, TimeUnit.SECONDS)
        .connectTimeout(10, TimeUnit.SECONDS);
}
 
源代码12 项目: DebugDrawer   文件: DebugViewActivity.java
private static OkHttpClient.Builder createOkHttpClientBuilder(Application app) {
    // Install an HTTP cache in the application cache directory.
    File cacheDir = new File(app.getCacheDir(), "okhttp3");
    Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);

    return new OkHttpClient.Builder()
        .cache(cache)
        .addInterceptor(LogsModule.chuckInterceptor(app))
        .addInterceptor(NetworkQualityModule.interceptor(app))
        .readTimeout(10, TimeUnit.SECONDS)
        .writeTimeout(10, TimeUnit.SECONDS)
        .connectTimeout(10, TimeUnit.SECONDS);
}
 
源代码13 项目: AndroidBlueprints   文件: ApiModule.java
@Provides
@Singleton
Cache provideOkHttpCache(Application application) {
    int cacheSize = 10 * 1024 * 1024; // 10 MiB
    return new Cache(application.getCacheDir(), cacheSize);
}
 
源代码14 项目: Xndroid   文件: BookmarkPage.java
@NonNull
private static File getFaviconFile(@NonNull Application application) {
    return new File(application.getCacheDir(), FOLDER_ICON);
}
 
源代码15 项目: Xndroid   文件: BookmarkPage.java
@NonNull
private static File getDefaultIconFile(@NonNull Application application) {
    return new File(application.getCacheDir(), DEFAULT_ICON);
}
 
源代码16 项目: droidconat-2016   文件: DataModule.java
@Provides @Singleton OkHttpClient.Builder provideOkHttpClientBuilder(Application app) {
    File cacheDir = new File(app.getCacheDir(), "http");
    Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);
    return new OkHttpClient.Builder().cache(cache);
}
 
源代码17 项目: Popular-Movies-App   文件: NetworkModule.java
@Provides
@Singleton
Cache providesOkHttpCache(Application application) {
    return new Cache(application.getCacheDir(), CACHE_SIZE);
}
 
源代码18 项目: JumpGo   文件: BookmarkPage.java
@NonNull
private static File getFaviconFile(@NonNull Application application) {
    return new File(application.getCacheDir(), FOLDER_ICON);
}
 
源代码19 项目: JumpGo   文件: BookmarkPage.java
@NonNull
private static File getDefaultIconFile(@NonNull Application application) {
    return new File(application.getCacheDir(), DEFAULT_ICON);
}
 
源代码20 项目: Xndroid   文件: FaviconModel.java
/**
 * Creates the cache file for the favicon
 * image. File name will be in the form of
 * [hash of URI host].png
 *
 * @param app the context needed to retrieve the
 *            cache directory.
 * @param uri the URI to use as a unique identifier.
 * @return a valid cache file.
 */
@WorkerThread
@NonNull
public static File getFaviconCacheFile(@NonNull Application app, @NonNull Uri uri) {
    FaviconUtils.assertUriSafe(uri);

    String hash = String.valueOf(uri.getHost().hashCode());

    return new File(app.getCacheDir(), hash + ".png");
}