Search code examples
androidandroid-intentandroid-file

How to make let the user select the location of the file which needs to be saved?


How do I make like this

When the user clicks to save the file an intent will get activated and tell the user where he wants to save that file


Solution

  • There is Storage Access Framework to do exactly this. There is a pretty good description in the Official documentation, so I just provide the simplest sample right here:

    const val CREATE_FILE = 1
    val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
        addCategory(Intent.CATEGORY_OPENABLE)
    }
    startActivityForResult(intent, CREATE_FILE)