0

how to make a folder in downloads folder and use it (reading and writing) in android 11 and up?

bard's code after getting permission:

 private fun createFolderInDownloads() { val intent = Intent(Intent.ACTION_CREATE_DOCUMENT) intent.addCategory(Intent.CATEGORY_OPENABLE) intent.type = "directory/*" val downloadsUri = File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .absolutePath + "/new folder" ) intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, downloadsUri) // Start activity for result to get user interaction startActivityForResult(intent, REQUEST_CREATE_FOLDER_CODE) } 

downloadsUri is printing the path i want but it didn't work (it doesn't make a file or throw an error)

5
  • downloadsUri is printing the path i want but it didn't work ? Then what should happen? What does not work? Commented Apr 15, 2024 at 15:16
  • intent.type = "directory/*" That is not usable for ACTION_CREATE_DOCUMENT which is for creating files. Commented Apr 15, 2024 at 15:18
  • and use it (like telegram) And how is it used in Telegram? How would we know what you are referring? Commented Apr 15, 2024 at 15:19
  • Then what should happen? What does not work? it doesn't make a file or throw an error Commented Apr 16, 2024 at 2:34
  • And how is it used in Telegram? How would we know what you are referring? i edited it Commented Apr 16, 2024 at 2:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.