Recently I've started to get ANR errors when call getExternalFilesDir(null)
from my activity code. This code was working earlier but now, maybe after updating gradle build tools, there is such problem. Cleaning the project and rebuild don't help. Did anyone get this problem also? Thanks in advance.
The sample of code. The app freezes with ANR dialog on the first line File folder = getExternalFilesDir(null);
// check if downloaded files take less memory than EPISODES_SIZE_WARNING_LIMIT_MB
private void checkFolderSize() {
File folder = getExternalFilesDir(null);
if (folder != null) {
long length = 0;
for (File file : folder.listFiles())
if (file.isFile())
length += file.length();
double sizeMb = ((double)length) / 1024 / 1024;
if (sizeMb > EPISODES_SIZE_WARNING_LIMIT_MB) {
new AlertDialog.Builder(this)
.setTitle(R.string.dialog_warning)
.setMessage(getString(R.string.warning_used_memory, EPISODES_SIZE_WARNING_LIMIT_MB))
.setNeutralButton(R.string.dialog_ok, null)
.show();
}
}
}