【问题标题】:Images not showing up in photos app, until I reboot my phone图片不会出现在照片应用程序中,直到我重新启动手机
【发布时间】:2015-05-08 03:51:34
【问题描述】:

正如您在下面的代码中看到的,我将位图保存到公共图片目录中。我还提供了存储中图像的屏幕截图,作为图像正在保存的进一步证据。

问题是图像不会显示在照片应用程序中,直到我重新启动手机。我检查了其他应用程序,这些图片立即出现。如果我打开图像,我也无法像其他图片一样编辑它(例如添加效果)。

 Bitmap b = Bitmap.createScaledBitmap(mBitmap, width, height, false);

                Long uuid = UUID.randomUUID().getMostSignificantBits();
            File path = Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_PICTURES + "/test");

            if(!path.exists() && !path.isDirectory()){
                path.mkdirs();
            }

            Log.i("Directory:", path.toString());

            File file = new File(path, "test_" + uuid + ".jpg");

            if (file.exists()){
                file.delete();
            }

            FileOutputStream out = null;
            try {
                out = new FileOutputStream(file);
                b.compress(Bitmap.CompressFormat.JPEG, 80, out);

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (out != null) {
                        out.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    });

【问题讨论】:

标签: java android file bitmap save


【解决方案1】:

添加新图片时必须发送通知

getContentResolver().notifyChange(
    Uri.parse("file://sdcard/abc.png");

【讨论】:

猜你喜欢
  • 2012-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多