Reputation:
I want to be able to create a folder for my app within "Internal Storage/" (on startup, if required) and later, within this folder, create any files (.txt) the user creates in the app.
These files must remain if the app is uninstalled, so use of getExternalFilesDir() - while it works - is not possible. I should note I don't want the user to have to use the file picker to create the folder or any files - ideally the app will take care of saving it to the app's public folder for them. So far I've tried using MediaStore and Storage Access Framework but have had little success. Just need a push in the right direction.
Note: I'm aware of getExternalStoragePublicDirectory(). It worked for what I need quite well, but I'd prefer not to use deprecated functions if possible. I also have the required permission in my manifest file, just having a hard time creating these files outside of my app's own folder within /data/
Thanks in advance anyone who can help :)
Upvotes: 1
Views: 324
Reputation: 368
Try this,
private fun getInternalLogFile(filename: String): File? =
File(
context.getDir(INTERNAL_DIRECTORY_NAME, Context.MODE_PRIVATE),
filename
)
INTERNAL_DIRECTORY_NAME is your folder name
Upvotes: 1