如何使用intent在指定文件夹中打开库

时间:2018-01-26 20:02:52

标签: java android android-studio android-intent

你能帮我看看如何使用意图打开指定文件夹中的图库吗? 它只打开指定文件夹中的图库(如下图所示)。

但是,它没有返回任何价值或活动。

我尝试了很多方法,但都没有打开指定的图库文件夹

我试过

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

这样可行,但只能打开图库,而不是在指定的文件夹

另一个

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/CameraExample/");
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));

这将打开最近的文件,但它不只是查看图库,而是选择一个文件,然后将其返回。

Intent intent = new Intent();
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/CameraExample/");
intent.setDataAndType(uri, "*/*");
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

它只显示白色屏幕。是否可以在指定的文件夹中打开图库?如果可能,它会像这样打开:

Screenshot - opening gallery in folder

2 个答案:

答案 0 :(得分:0)

  

是否可以在指定文件夹中打开图库?

不,抱歉。

答案 1 :(得分:0)

图库选择并非旨在从任何位置打开。支持的位置:

  1. 相册位置( / SD卡/ DCIM)