I have developing my android app and testing it in the lowest supported SDK, which is API 18 Jellybean through an emulator (Genymotion). There is a use case where I have to download a pdf file and save it in the external storage. This works as expected in the API 18 emulator without any trouble. Then i decided to test it in my own device, which is a Huawei Honor6x with API 24, but i got a FileNotFoundException. After debugging i figured out that its not creating the directory in the external storage. To cross check if this is a problem specific to my own device, I installed 2 other emulators with API 24 (Pixel XL and Galaxy S7). I got the same error. Is there any security features blocking me from creating a folder in never versions?
here is my code
I have the following permissions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
And here is the code where i create the directory
File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "/notespal");
if (!directory.exists()){
boolean created = directory.mkdirs();
}
Appreciate your assistance since i have been stuck in this for few days now.