get Cache Directory - Android Hardware

Android examples for Hardware:Cache Folder

Description

get Cache Directory

Demo Code


//package com.java2s;

import android.content.Context;

import java.io.File;

public class Main {
    public static String getCacheDir(Context context) {
        String cachePath;//from   www .j a  va  2 s  .co  m
        File file = context.getExternalCacheDir();
        // 
        // http://stackoverflow.com/questions/16562165/getexternalcachedir-returns-null-after-clearing-data
        if (file != null) {
            cachePath = file.getPath();
        } else {
            cachePath = context.getCacheDir().getPath();
        }
        return cachePath;
    }
}

Related Tutorials