【问题标题】:Load Images folder in android gallery在 android 库中加载图像文件夹
【发布时间】:2012-02-15 12:25:09
【问题描述】:

我正在开发一个应用程序,我从相机拍摄照片并将其存储在 SD 卡中的单独文件夹中。我面临的问题是,一旦图片存储在 sd 卡上的文件夹中,图像文件夹就不会显示在 android 本机图库中。 这应该类似于 whatsapp 图像文件夹。怎么可能?

【问题讨论】:

  • 你有没有在 manifest 文件中添加 android.permission.WRITE_EXTERNAL_STORAGE 权限
  • 我可以将图像存储在 sd 卡上,但我的问题是我想在 android 的原生图库中显示这些图像
  • 我不完全确定,但也许你必须告诉 android,有新文件。尝试搜索 MediaStore 和 MediaScanner。

标签: android image image-gallery


【解决方案1】:

使用函数 MediaStore.Images.Media.insertImage 创建缩略图并在默认的 android 库中显示图像。

String imageName = "imagepath";

文件 sdImageMainDirectory = new File(imageName);

MediaStore.Images.Media.insertImage(getContentResolver(), sdImageMainDirectory.getAbsolutePath(),sdImageMainDirectory.getName(), "描述");

【讨论】:

    【解决方案2】:

    您需要让系统知道新媒体已添加,然后才会显示。保存图像后调用它。

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      • 2012-07-28
      • 2012-08-24
      • 1970-01-01
      相关资源
      最近更新 更多