Trying open a specific folder in android using int

2020-02-05 03:09发布

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


            }
       });

4条回答
Bombasti
2楼-- · 2020-02-05 03:50

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 )
查看更多
Viruses.
3楼-- · 2020-02-05 03:50

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);
查看更多
唯我独甜
4楼-- · 2020-02-05 03:54

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


            }
       });
查看更多
爱情/是我丢掉的垃圾
5楼-- · 2020-02-05 04:01

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

查看更多
登录 后发表回答