0

This code works perfectly until you clear cache from Device's Settings/App/your app menu.

/**
 * @param context te get packageName & {@code cacheDir} from internal storage

 * @return file for {@code cacheDir} either SD card or internal storage. Or {@code null} if cacheDir doesn't exist
 */
public static File getCacheDir(Context context) throws IOException {
    File cacheDir;
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        String cacheDirPath = getApplicationCacheDirPath(context.getPackageName());
        cacheDir = new File(Environment.getExternalStorageDirectory() + File.separator + cacheDirPath);
    } else {
        cacheDir = context.getCacheDir();
    }

    if (cacheDir != null && !cacheDir.exists()) {
        if (!cacheDir.mkdirs()) {
            throw new IOException("Can't use cacheDir");
        }
    }
    return cacheDir;
}

I've tried to delete this file and create it again, as a workaround, to release lock by some other(system) app, and that failed also. Only device's reboot do solve that problem. Any help would be appreciated. Thank you!

Roger Alien
  • 3,040
  • 1
  • 36
  • 46
  • `I Can't create directory` `I've tried to delete this dir,` ???? Unclear what you want. – greenapps Jan 31 '16 at 19:11
  • @greenapps I want to create a directory, I've found a kind a workaround, where decribed that you can try to delete that file, if creation is failed, and try again, but file is being blocked. – Roger Alien Feb 01 '16 at 07:03
  • Well i see no file. Only a directory. You are invited to edit your post until you have an understandeble problem. – greenapps Feb 01 '16 at 17:24

0 Answers0