簡體   English   中英

以編程方式移動照片后如何更新圖庫?

[英]how to update gallery after moving photo programmatically?

我正在使用以下代碼將照片從目錄移動到另一個目錄

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更新文件的邏輯是錯誤的,應該怎么辦?

謝謝。

從圖庫中刪除

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);
                        }
                    });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM