List of usage examples for android.content Context getExternalCacheDirs
public abstract File[] getExternalCacheDirs();
From source file:com.androidzeitgeist.dashwatch.common.IOUtil.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static File getBestAvailableCacheRoot(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // In KitKat we can query multiple devices. // TODO: optimize for stability instead of picking first one File[] roots = context.getExternalCacheDirs(); if (roots != null) { for (File root : roots) { if (root == null) { continue; }/*w w w. ja v a2 s .co m*/ if (Environment.MEDIA_MOUNTED.equals(Environment.getStorageState(root))) { return root; } } } } else if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { // Pre-KitKat, only one external storage device was addressable return context.getExternalCacheDir(); } // Worst case, resort to internal storage return context.getCacheDir(); }