插入新图片Gallery不更新

来源:互联网 发布:淘宝 有哪些 家具店 编辑:程序博客网 时间:2024/06/10 09:12

目前在做一个应用,需要在应用中保存图片到照片目录  /mnt/sdcsrd/DCIM/Camera ,但是图片保存以后在Gallery 中看不到插入的图片。

搜了很多网站,终于找到解决方法:

插入图片后,运行 Media scanner,更新图片库:

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

另外需要在 AndroidManifest.xml  中添加语句:

            <intent-filter >                <action android:name="android.intent.action.MEDIA_MOUNTED" />                <data android:scheme="file" />            </intent-filter>


再运行就可以正常更新了。