尝试使用intent打开android中的特定文件夹

use*_*466 14 android android-intent

我想在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"));


            }
       });
Run Code Online (Sandbox Code Playgroud)

vin*_*eti 8

public void openFolder()
{
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"));
}
Run Code Online (Sandbox Code Playgroud)

"*/*"也可以使用其他MIME类型.

  • 我使用上面的代码,它说你需要使用drop box app ????? 我只需要在android中打开一个特定的文件夹 (2认同)

Aya*_*fov 5

有用:

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

有一个很好的编码:)

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

  • 错误:未找到处理 PATH 的活动,类型=“资源/文件夹” (5认同)
  • 我的设备上安装了“Root Explorer”。还有默认的文件管理器。但仍然出现错误。 (3认同)
  • 此代码仅在您拥有 ES 文件浏览器时才有效。需要更改`setDataType` (3认同)

raj*_*ree 1

尝试用这一行替换您的代码

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


            }
       });
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

27235 次

最近记录:

7 年,5 月 前