扫描Android的SD卡的新文件新文件、Android、SD

2023-09-12 21:38:35 作者:寂寞才说爱

我的应用程序允许用户将图像保存到他们的SD卡。但我不知道怎么做,直到你卸载并重新挂载SD卡也出现在画廊。我用Google搜索了这个问题了两天,但我不知道如何使它自动出现。我发现 这的链接,但我不知道如何使用类。这是我用什么来保存文件。在try catch块的底部是我想要的扫描SD卡新媒体。

My app allows a user to save an image to their SD card. But I'm not sure how to make it appear in the gallery until you unmount and remount the SD card. I have googled for a couple of days with this problem but am not sure how to make it appear automatically. I found this link but I'm not sure how to use the class. This is what i use to save the file. At the bottom of the try catch block is where I want to scan the sd card for new media.

    FileOutputStream outStream = null;
    File file = new File(dirPath, fileName);
    try {
        outStream = new FileOutputStream(file);
        bm.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
        outStream.flush();
        outStream.close();
    } catch {
         ...
    }

如果任何人都可以点我在正确的方向,我想AP preciate。

If anyone could point me in the right direction, I would appreciate.

推荐答案

由于最后的答案我张贴显然不是一个合适的方法,我发现了另一个方法here.基本上,你创建一个包装类,对其进行初始化,然后调用扫描()方法。非常有帮助的帖子。让我知道这是不恰当的无论是。

Since the last answer I posted apparently wasn't an appropriate method, I found another method here. You basically create a wrapper class, initialize it, and then call the scan() method. Very helpful post. Let me know if this isn't appropriate either.