以编程方式移动照片后如何更新图库?

我使用以下代码将照片从目录移动到另一个目录

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秒或更多所以给我build议我应该做什么,如果逻辑更新文件使用sendBroadcast是错误的?

谢谢。

Solutions Collecting From Web of "以编程方式移动照片后如何更新图库?"

从画廊中删除

 try { getContentResolver().delete(); } catch (Exception e) { e.printStackTrace(); } 
 if (Build.VERSION.SDK_INT < 19) mContext.sendBroadcast(new Intent( Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); else { MediaScannerConnection .scanFile( mContext, new String[]{imageFile.toString()}, null, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted( String path, Uri uri) { Log.i("ExternalStorage", "Scanned " + path + ":"); Log.i("ExternalStorage", "-> uri=" + uri); } }); }