如何在Android中以编程方式向画廊添加图像或以编程方式刷新画廊 [英] How to add images to gallery programmatically in android or refresh gallery programmatically

查看:57
本文介绍了如何在Android中以编程方式向画廊添加图像或以编程方式刷新画廊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将某些图像从服务器下载到文件夹中的sd卡中.图像已成功存储在sd卡中.但是问题在于,图像同时没有在图库中显示.如果我重新启动设备,则它将显示在图库中.

I am downloading some of the images from server to sd card in a folder. Images are storing in sd card successfully. But the problem is that at the same time images are not showing in gallery. If i restart the device then it will be showing in gallery.

如何以编程方式刷新图库,以便每当我从服务器获取图像时都可以同时看到图像?

How can I refresh the gallery programmatically so images can be visible simultaneously whenever I fetch images from server?

推荐答案

我明白了,下面的代码将扫描您的图像文件,并将其同时提供给图库:

I got it, below code will scan your image file and make it available simultaneously to gallery also:

MediaScannerConnection.scanFile(context,
            new String[] { file.toString() }, null,
            new MediaScannerConnection.OnScanCompletedListener() {
        public void onScanCompleted(String path, Uri uri) {
            Log.i("ExternalStorage", "Scanned " + path + ":");
            Log.i("ExternalStorage", "-> uri=" + uri);
        }
    });

这篇关于如何在Android中以编程方式向画廊添加图像或以编程方式刷新画廊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆