Permalink
Browse files

[sample] Only use external storage for disk cache if it's usable.

  • Loading branch information...
1 parent b34e45b commit 1fc2edef1324fcb9e2839efd2569bc73d6b6f36e @chrisbanes committed Feb 21, 2013
Showing with 10 additions and 2 deletions.
  1. +10 −2 sample/src/uk/co/senab/bitmapcache/samples/SampleApplication.java
@@ -31,8 +31,16 @@
public void onCreate() {
super.onCreate();
- File cacheLocation = new File(
- Environment.getExternalStorageDirectory() + "/Android-BitmapCache");
+ File cacheLocation;
+
+ // If we have external storage use it for the disk cache. Otherwise we use
+ // the cache dir
+ if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
+ cacheLocation = new File(
+ Environment.getExternalStorageDirectory() + "/Android-BitmapCache");
+ } else {
+ cacheLocation = new File(getFilesDir() + "/Android-BitmapCache");
+ }
cacheLocation.mkdirs();
BitmapLruCache.Builder builder = new BitmapLruCache.Builder();

0 comments on commit 1fc2ede

Please sign in to comment.