Не создаётся директория на андроид
При попытке создать директорию
filePath.getParentFile().mkdirs();
возвращает False. Разрешения в Manifest даны
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
При нажатии на кнопку динамически проверяется присутствие разрешения. Собственно сам код:
case R.id.buttonCreateWaybill:
if ((checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) && (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED)) {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellValue("test");
File filePath = new File(Environment.getExternalStorageDirectory() + File.separator + "Waybills", "demo.xls");
try {
if (!filePath.getParentFile().exists()) {
filePath.getParentFile().mkdirs();
}
if (!filePath.exists()) {
filePath.createNewFile();
}
FileOutputStream fileOutputStream = new FileOutputStream(filePath);
workbook.write(fileOutputStream);
if (fileOutputStream != null) {
fileOutputStream.flush();
fileOutputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
break;