note: when I say root, I mean the folder where the download, documents, music, android folders are located, etc…
Environment.getExternalStoragePublicDirectory
Guys, I'm new to the android ecosystem, I'm not a professional programmer, but I come from PHP, i'm learning kotlin on the internet, and i started making an app, a download manager to be more specific, this app downloads the file in 8 parts i have other problems but i'm currently stuck in the directory, For example my app goes from api 21 to 31, I was testing on api 29 in this version of the system the method
File(Environment.getExternalStoragePublicDirectory("/my folder").toString())
works both to create directories and files, in api 29 I already get the information that it is deprecated. The problem starts from api 30 where this method no longer works. And I'm not understanding the documentation because it seems that the methods change in api 30 to 31, it has a permission “android.permission.MANAGE_EXTERNAL_STORAGE”, but the play store only accepts it if the app really needs it from what I understand, and I don't I understand if it is valid for api 29 or 30 and no longer works on 31.
I assume I'm not a high-performing intelligent person, but from what I've noticed Google changes the codes a lot and in a short time.
So far the only directory that everything works without problems is the private folder that the system creates for the application, but this folder is a little hidden because it is in the folder Android/data/nameApp/files/ I would like to save it as in the previous apis where I created a folder
File(Environment.getExternalStoragePublicDirectory("/my folder").toString())
and inside that folder I created other subfolders like document, compress, program, audio, video, other and saved the files in their respective folder.
How can I do this from api 30+, I don't want to have permission to access all android folders just all folders inside the folder I create in the root directory, another reason I don't want to use the app's private folders is that if it is uninstalled all files downloaded inside them will be deleted automatically.
What approach do you recommend for this situation?
Another problem I found is that from api 30 onwards the File class became very slow. As I download the file in parts I was using the RandomAccessFile(File(pathFile), "rw") class to write the 8 parts simultaneously with:
withContext(Dispatchers.Main) {
for (part in parts){
launch(Dispatchers.IO) {
startDownload(.....)
}
}
}
Where parts contains all the information of the parts to perform the download, but as File was slow I noticed that the download speed decreased a lot compared to previous apis and apparently RandomAccessFile only accepts the File class. Does anyone have an idea to work around this other problem?
I thank the help of all.