如何更新编程移动照片后,库? [英] how to update gallery after moving photo programmatically?

查看:228
本文介绍了如何更新编程移动照片后,库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感动的照片从目录到另一个使用以下code

I am moving photo from on directory to another using following code

File oldfile= new File(originalImagePath);              
File newfile=new File(newImagePath);
boolean d=oldfile.renameTo(newfilee);
if(d){

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + newfilee.getPath())));
 }

照片移到新目录成功,但它要花很长的时间时的照片都比较计约30秒后,更新画廊和画廊更新或多个所以给我的建议,我应该做的,如果逻辑使用sendBroadcast是错误的更新文件?

photos moved to new directory successfully but it take too long time when photos are more in count to update gallery and gallery updates after around 30 seconds or more So give me suggestion what I should do if logic to update file using sendBroadcast is wrong?

感谢。

推荐答案

我发现以下解决方案,并为我工作得很好

I have found following solution and that worked fine for me

从库中删除

try {

  getContentResolver() .delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
          MediaStore.Images.Media.DATA
              + "='"
              + file.getPath()
              + "'", null);
   } catch (Exception e) {
        e.printStackTrace();

  }

和在库添加媒体

ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, newfilee.getPath());
values.put(MediaStore.Images.Media.DATE_TAKEN, newfilee.lastModified());

Uri mImageCaptureUri = getActivity().getContentResolver()
.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);

        // to notify change         
     getActivity().getContentResolver().notifyChange(
        Uri.parse("file://" + newfilee.getPath()),null);

这篇关于如何更新编程移动照片后,库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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