Home > Net >  How to start Intent.ACTION_GET_CONTENT in a specific location?
How to start Intent.ACTION_GET_CONTENT in a specific location?

Time:01-31

I am trying to open a directory for user to choose an excel document from it. However, my file picker opens in the "recent" location. Is there a way to start it from a specific directory using new versions of Android?

This is my code:

 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                    Uri uri = Uri.parse(Environment.DIRECTORY_DOCUMENTS);
                    intent.setDataAndType(uri, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                    startActivity(Intent.createChooser(intent, "Open folder"));

CodePudding user response:

You need to set EXTRA_INITIAL_URI:

intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)

CodePudding user response:

Unfortunately, the Intent.ACTION_GET_CONTENT does not support opening in a specific location. The only way to choose a specific location is by using a third-party file picker library, such as FilePicker, aFileChooser, etc.

You can use these libraries to create a custom file picker that opens in a specific location and allows the user to choose a file. Then, you can call the custom file picker in your code instead of using Intent.ACTION_GET_CONTENT.

  • Related