Before scoped storage app could create set of files like this
if(isStoragePermissionGranted()){
val textFileDir = File(Environment.getExternalStorageDirectory(), getString(R.string.app_name)+"/"+"Textfiles/")
textFileDir.mkdir()
for(i in 0 until 5){
val textfile = File(textFileDir, String.format("%s-%s.txt", "TextFile", i))
textfile.writeText("Content")
}
}
But with the scoped storage every file that we create has to be given permission separately
const val CREATE_FILE = 1
private fun createFile(pickerInitialUri: Uri) {
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "text/plain"
putExtra(Intent.EXTRA_TITLE, "invoice.txt")
putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)
}
startActivityForResult(intent, CREATE_FILE)
}
How can we create set of text files and writing content to them at once without giving permission one by one using access storage framework.
This is how i was able to create multiple files. I followed @Commonsware suggestion