安卓:保存新的图像后刷新图库 [英] Android: Refreshing the Gallery after saving new images

查看:363
本文介绍了安卓:保存新的图像后刷新图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,在我的应用程序在一个点上一堆图像保存到临时文件夹,我希望他们在画廊立即显示。关闭重启的,他们这样做,但除此之外,他们没有。

So in my application I at one point save a bunch of images to a temporary folder, and I want them to show up immediately in the Gallery. Off of a reboot, they do, but otherwise they don't.

我已经使用sendBroadcast方法尝试:

I've tried using the sendBroadcast method:

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

不过,我得到一个权限错误:

But I get a permission error:

E/AndroidRuntime( 2628): java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=2628, uid=10068

难道我缺少权限在我AndroidManifest,或者这只是不再支持?谢谢

Could I be missing a permission in my AndroidManifest, or is this just no longer supported? Thanks

推荐答案

试试这个,它为我的奇巧(4.4) HTTP ://stackoverflow.com/a/5814533/640528

Try this, It works for me on Kitkat (4.4) http://stackoverflow.com/a/5814533/640528

        MediaScannerConnection.scanFile(this, new String[] { Environment.getExternalStorageDirectory().toString() }, null, new MediaScannerConnection.OnScanCompletedListener() {
            /*
             *   (non-Javadoc)
             * @see android.media.MediaScannerConnection.OnScanCompletedListener#onScanCompleted(java.lang.String, android.net.Uri)
             */
            public void onScanCompleted(String path, Uri uri) 
              {
                  Log.i("ExternalStorage", "Scanned " + path + ":");
                  Log.i("ExternalStorage", "-> uri=" + uri);
              }
            });

这篇关于安卓:保存新的图像后刷新图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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