With new versions of the Android, it is becomes harder and harder to access storage via some APIs. The FileF collects 4 different approaches to access storage in Android, which work with fine until the Android 10. Android 11 and higher requires MANAGE_APP_ALL_FILES_ACCESS_PERMISSION to access all the files in the background via older APIs. If the app needs this permissions and is released on Google Play, it needs to serve specific purpose like file browser, antivirus, ... - more on that here. Otherwise, you should use scoped storage - more here.
The app takes folders as inputs and number of the number of the biggest files to be found. Also you can choose algorithm, which will search the folders. The app supports parallel search in SD card and external memory of the phone.
- File API - The Android can use java old-fashioned File API, which is compatible with all the Android versions - in my tests the fastest
- Nio Files API - Compatible with Android Oreo and higher - have its own implementation to walk through the all folders
- Content resolver - usage of queries to find files in the folder - unfortunately, the conditions for the query are ignored and is the slowest among the APIs
- Apache Commons IO - wrapper for the Nio Files API, which can be used in lower versions of the Android
The main folder of the app is 'utils', where all the methods can be found:
- sorters
- BiggestFileGatherer.kt - Keeps sorted array by size. Insertion is being done by InsertionSort. Accepts File, Uri, Path objects.
- Sorting.kt - InsertionSort and QuickSort implementations
- types - SavedFile.kt - basic object, which saves path, uri and size of the file
- walkers
- Walker.kt - abstract class, which has BiggestFileGatherer and method to customized, so the walkers are in organized manner
- implementations: WalkerApacheIO.kt / WalkerContentResolver.kt / WalkerFiles.kt / WalkerFilesOreo.kt
- CustomFileUtils.kt - helper functions to get path to SD, adding to Sets, duplication preventions, ...
- WalkerFactory.kt - generates the required Walker
- WalkerIterator.kt - takes list of the folders to be searched in, iterates through them and merges the results of all folders into one
- WalkerListener.kt - interface, which the UI should have, so it can show the progress
- Apache Commons IO - Apache Commons IO is a library of utilities to assist with developing IO functionality.
- SimpleStorage - 💾 Simplify Android Storage Access Framework for file management across API levels.
- Toasty - The usual Toast, but with steroids 💪