I have tried so many answers related to this question but didn't work any of them. this my code but it didn't open the myFile folder. Please help me to resolve this issue
val intent = Intent(Intent.ACTION_GET_CONTENT)
val uri = Uri.parse(
(Environment.getExternalStorageDirectory().absolutePath) + "/myFile/")
intent.setDataAndType(uri, "*/*")
startActivityForResult(intent, WRITE_ACCESS_CODE)
If you want to open a specific folder: Intent intent = new Intent (Intent.ACTION_GET_CONTENT); intent.setDataAndType (Uri.parse (Environment.getExternalStorageDirectory ().getPath () + File.separator + "myFolder" + File.separator), "file/*"); startActivityForResult (intent, YOUR_RESULT_CODE);
To do this, phones with Android Marshmallow or Nougat installed come with their own file manager that can access this full partition. This option is hidden away under Settings > Storage > Other. Some phones on older versions of Android may or may not include their own file explorer, depending on the OEM.
The framework provides several methods to help you access and store files in this directory. You can use the File API to access and store files. To help maintain your app's performance, don't open and close the same file multiple times.
On Android 4.4 (API level 19) or higher, your app doesn't need to request any storage-related permissions to access app-specific directories within external storage. The files stored in these directories are removed when your app is uninstalled.
This code may help you:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, YOUR_RESULT_CODE);
If you want to open a specific folder:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setDataAndType(Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ File.separator + "myFolder" + File.separator), "file/*");
startActivityForResult(intent, YOUR_RESULT_CODE);
try this -->
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ File.separator + "myFolder" + File.separator);
intent.setDataAndType(uri, "text/csv");
startActivity(Intent.createChooser(intent, "Open folder"));
OR
// location = "/sdcard/my_folder";
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri mydir = Uri.parse("file://"+location);
intent.setDataAndType(mydir,"application/*"); // or use */*
startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With