@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;
                    }
                    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();
    }
@TargetApi(Build.VERSION_CODES.KITKAT)
    public static File getBestAvailableCacheRoot(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
           
           
            File[] roots = context.getExternalCacheDirs();
            if (roots != null) {
                for (File root : roots) {
                    if (root == null) {
                        continue;
                    }
                    if (Environment.MEDIA_MOUNTED.equals(Environment.getStorageState(root))) {
                        return root;
                    }
                }
            }
        } else if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
           
            return context.getExternalCacheDir();
        }
       
        return context.getCacheDir();
    }
@targetapi(build.version_codes.kitkat) public static file getbestavailablecacheroot(context context) { if (build.version.sdk_int >= build.version_codes.kitkat) { file[] roots = context.getexternalcachedirs(); if (roots != null) { for (file root : roots) { if (root == null) { continue; } if (environment.media_mounted.equals(environment.getstoragestate(root))) { return root; } } } } else if (environment.media_mounted.equals(environment.getexternalstoragestate())) { return context.getexternalcachedir(); } return context.getcachedir(); }