【问题标题】:Android - How to open a specific folder in a gallery using an implicit intent?Android - 如何使用隐式意图打开画廊中的特定文件夹?
【发布时间】:2015-11-01 03:11:44
【问题描述】:

我们正在构建一个相机应用程序,将照片保存在图库中的特定文件夹中。我们必须使用意图在图库中打开我们应用程序的文件夹。我们正在使用此代码,但它显示了所有文件夹。

View.OnClickListener goToGallery = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        intent.setType("image/*");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
};

【问题讨论】:

标签: java android android-intent


【解决方案1】:

为了打开画廊,我使用了这个意图。

public static final int RESULT_GALLERY = 0;

Intent galleryIntent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(galleryIntent , RESULT_GALLERY );

【讨论】:

  • 感谢您的回答。但是,我们不需要选择照片,我们只需要在图库中查看我们文件夹中的照片 :)
  • 我不完全确定,但请尝试将 ACTION_PICK 替换为 ACTION_VIEW 为我上面的代码。
【解决方案2】:

试试这个代码。 它将检索storage/emulated/0/Pictures/MyAppPics下的视图图片 您可以根据自己的目录路径更改文件路径。

File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File f = new File(sdDir, "MyAppPics");

Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.withAppendedPath(Uri.fromFile(f), "/MyAppPics"), "image/*");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

【讨论】:

  • 为此,是否必须在 storage/emulated/0/Pictures 中有图像?我的图像位于内存中的一个文件夹中。而且这个解决方案对它不起作用。
猜你喜欢
  • 2018-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-05
  • 2014-02-27
  • 1970-01-01
相关资源
最近更新 更多