Home Automation Home Assistant eBook Applied Artificial Intelligence eBook Cryptocurrency Blockchain Bitcoin ebook eBook TabShop Android Point of Sale (POS)

Android Permission Error in File Cache Loading

java.io.FileNotFoundException: /storage/emulated/0/TempImages/: open failed: ENOENT (No such file or directory)

Android 11 onwards introduced several more restrictive policies for applications to access the local storage. It is necessary to request the users permission for access in the context of usage not only to declare the access rights in the Android manifest file.

See the Android error message below:

java.io.FileNotFoundException: open failed: EACCES (Permission denied)

Some storage directories are accessible nevertheless, such as the public download directory or the applications own directory.

To store chached files such as images that your application loads, you should switch to your own apps local cache directory:

fileCache = new FileCache(context);

The switch from the Android environment file cache directory to the apps own file cache directory avoids the annoying permission requests and access exceptions.