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.
Asked
Active
Viewed 32 times
1 Answers
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.

Community
- 1
- 1