【问题标题】:How to open a picture in gallery如何在图库中打开图片
【发布时间】:2016-05-05 23:22:07
【问题描述】:

我想在画廊中打开一张图片。图库路径为 root + "/saved_images",其名称为 fname。它打开画廊,我可以选择那张照片,但我想直接打开那张照片。

String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
String fname = "Image-" + formattedDate + ".jpg";

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(root + "/saved_images"+fname), "image/*");
startActivity(intent);

【问题讨论】:

标签: android eclipse android-intent image-gallery


【解决方案1】:

您需要将 file:// 添加到路径中,如下所示: intent.setDataAndType(Uri.parse("file://" + root + "/saved_images/"+fname), "image/*");

【讨论】:

    【解决方案2】:

    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString()"/storage/emulated/0/Pictures" 的形式返回给你一些东西。

    为了有一个有效的Uri,它只是在你的文件路径前面错过了"file://"

    此外,如果"saved_images" 是一个目录,则在目录名和文件名之间缺少/

    一起

    intent.setDataAndType(Uri.parse("file://" + root + "/saved_images/" + fname), "image/*");
    

    应该做的工作。

    【讨论】:

      猜你喜欢
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-10
      • 1970-01-01
      • 2014-09-29
      • 2020-03-16
      相关资源
      最近更新 更多