At first, the file is saved without any issue, but after a few clicks, it shows an error: "Cannot delete file at Documents/math.csv." As a result, new files are created with names like math.csv (1), math.csv (2), and so on. and also asking for permission.
just changed scope from shared to app then its not asking for permission and working fine. Please tell me why its asking for shared scope, i want to learn..
Note:
If your app is also intended to run on Android devices below 11, storage permissions must of course be requested. However, in this case, it is sufficient to only request WRITE_EXTERNAL_STORAGE permission, as this also implicitly grants READ permission.
Both permissions (READ & WRITE, but only these two) are declared in the Manifest and can/must therefore be requested on Android ≤ 10.
Is it possible for the 'Pralaya' folder in the Documents directory to be automatically deleted upon app uninstallation? Currently, when I uninstall the app, the 'Pralaya' folder remains and is not deleted.
No. You should leave the folder (and file) in the ASD, as it will be automatically deleted when the app is uninstalled. Otherwise, your only option is to delete the folder each time the app goes to the background and recreate the folder and file when the app returns to the foreground.
If the app is uninstalled and reinstalled, the newly installed app will be a new app. Therefore, the existing file cannot be overwritten. The possible solution is the one I described.