21

I am trying to open a specific folder in android ?Is it possible to open a specific folder ???? this is the code i m using

    config=(Button)findViewById(R.id.btn_cf);

      config.setOnClickListener(new View.OnClickListener() 
      {         
            @Override
            public void onClick(View v)
            { 

            Intent intent = new Intent("Intent.ACTION_GET_CONTENT"); 
             Uri uri = Uri.parse("mnt/sdcard/myfiles/allfiles/download"); 
            intent.setDataAndType(uri, "*/*"); 
            startActivity(Intent.createChooser(intent, "download"));


            }
       });
user3269466
  • 221
  • 1
  • 2
  • 5
  • 1
    have you tried this link http://stackoverflow.com/questions/17165972/android-how-to-open-a-specific-folder-via-intent-and-show-its-content-in-a-file – Deniz Feb 04 '14 at 05:09

4 Answers4

5

It works:

Uri selectedUri = Uri.parse(Environment.getExternalStorageDirectory() + "/myFolder/");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedUri, "resource/folder");
startActivity(intent); 

Have a nice codding :)

EDIT: If the current solution doesn't help you, then these file/directory choosers libraries can be helpful: https://android-arsenal.com/tag/35

Ayaz Alifov
  • 8,334
  • 4
  • 61
  • 56
1

try to replace your code with this line

  btn.setOnClickListener(new View.OnClickListener() 
      {         
            @Override
            public void onClick(View v)
            { 

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


            }
       });
rajshree
  • 790
  • 5
  • 19
0

I found a solution in this GitHub repo

The code :

If you want open & browse file: FileBrowser.class

        Intent intent = new Intent(activity, FileBrowser::class.java)
        intent.putExtra(Constants.INITIAL_DIRECTORY, File(storageDirPath).absolutePath)
        intent.putExtra(Constants.ALLOWED_FILE_EXTENSIONS,"*")

        startActivityForResult(intent, CODE_INTENT )

If you want to get user chosen file's URI: FileChooser.class

        Intent intent = new Intent(activity, FileChooser::class.java)
        intent.putExtra(Constants.INITIAL_DIRECTORY, File(storageDirPath).absolutePath)
        startActivityForResult(intent, CODE_INTENT )
exploitr
  • 843
  • 1
  • 14
  • 27
Serg Burlaka
  • 2,351
  • 24
  • 35
-1

Pick root:

Intent selectFile = new Intent(); 
                             selectFile.setAction("com.sec.android.app.myfiles.PICK_DATA_MULTIPLE");    
            selectFile.putExtra("CONTENT_TYPE", "*/*");
            selectFile.addCategory(Intent.CATEGORY_DEFAULT);
            startActivity(selectFile);
nKn
  • 13,691
  • 9
  • 45
  • 62
Dragonfly
  • 7
  • 1