Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open specific folder in the storage using intent in android

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)

This is the result of this code. Only open the recent page

like image 201
Sanush Avatar asked Jul 08 '20 06:07

Sanush


People also ask

How do I open a specific folder with an intent?

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);

How do I open the full storage on my Android phone?

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.

How do I access and store files in the app's directory?

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.

What permissions does my Android app need to access external storage?

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.


Video Answer


2 Answers

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);
like image 111
Cardstdani Avatar answered Oct 02 '22 00:10

Cardstdani


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);
like image 36
Wini Avatar answered Oct 02 '22 01:10

Wini