尝试使用 Intent 在 android 中打开特定文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21544331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:43:32  来源:igfitidea点击:

Trying open a specific folder in android using intent

androidandroid-intent

提问by user3269466

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

我正在尝试在 android 中打开特定文件夹?是否可以打开特定文件夹????这是我使用的代码

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


            }
       });

回答by rajshree

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


            }
       });

回答by Ayaz Alifov

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

编辑:如果当前的解决方案对您没有帮助,那么这些文件/目录选择器库可能会有所帮助:https: //android-arsenal.com/tag/35

回答by Serg Burlaka

I found a solution in this GitHub repo

我在这个GitHub repo 中找到了一个解决方案

The code :

编码 :

If you want open & browse file:FileBrowser.class

如果你想打开和浏览文件: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

如果您想获取用户选择的文件的 URI:FileChooser.class

        Intent intent = new Intent(activity, FileChooser::class.java)
        intent.putExtra(Constants.INITIAL_DIRECTORY, File(storageDirPath).absolutePath)
        startActivityForResult(intent, CODE_INTENT )

回答by Dragonfly

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