0

I try to click on a menu item with the help of this method to open a specific folder that the app creates in internal memory when .txt file is recorded, but this is not possible even though the folder exists. Can you help me when I click the menu item to open MyFolder, please.

switch (item.getItemId()) {

    case R.id.openFolder:

                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
                        + "/MyFolder/");
                intent.setDataAndType(uri, "text/csv");
                startActivity(Intent.createChooser(intent, "Open folder"));

            break;

}
janDe
  • 43
  • 1
  • 7
  • Just FYI, getExternalStorageDirectory() is deprecated and won't be returning anything if your compile Android version is Q or higher. – Azhar92 Aug 11 '19 at 04:05
  • I believe you are right and i have to agree with you. Is there any method you can write in the comment? Thank you – janDe Aug 11 '19 at 11:56

1 Answers1

0

First of all, I would check if there is some file explorer on the system that would handle a request of opening directories this is an example.


Then your code should be modified to:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/MyFolder/");
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));

also you may create the uri like this and I am not sure why this prefix is needed sometimes, maybe someone can explain to us:

Uri uri = Uri.parse("file://" + Environment.getExternalStorageDirectory().getPath()+ "/MyFolder/");
Atef Hares
  • 4,715
  • 3
  • 29
  • 61