0

I want to check where my apps cache is raising all the time. So I need a method to access informations about the current cache at any time. I think there must be such a method, because I could see the size of the cache in the App-Info of my android-smartphone. The app is running in the background and I want to log when the size of the cache is raising.

user3890967
  • 43
  • 1
  • 6

1 Answers1

1

Use below code snippets for your solution.

public static byte[] retrieveData(Context context, String name) throws IOException {

        File cacheDir = context.getCacheDir();
        File file = new File(cacheDir, name);

        if (!file.exists()) {
            // Data doesn't exist
            return null;
        }

        byte[] data = new byte[(int) file.length()];
        FileInputStream is = new FileInputStream(file);
        try {
            is.read(data);
        }
        finally {
            is.close();
        }

        return data;
    }

Here is complete CacheManager class.

When to clear the cache dir in Android?

Community
  • 1
  • 1