Deleted image still shows in android gallery untill I restart the emaulator

前端 未结 3 1572
别跟我提以往
别跟我提以往 2021-01-13 14:06

I\'m deleting a file as such

File fileToDelete =  new File(\"filepath\");
Boolean fileDeleted =  fileToDelete.delete();

The fileDeleted is

3条回答
  •  清歌不尽
    2021-01-13 14:20

    I use the following code (which is also much like my code for creating a video which also tells the media system about file changes and correctly updates the Gallery):

    private void deleteVideo(String videoUrl)
    {
        File videoFile = new File(videoUrl);
        if (!videoFile.delete())
        {
            Log.e(TAG, "Failed to delete " + videoUrl);
        }
        else
        {
            MediaScannerConnection.scanFile(mContext,new String[] { videoUrl }, null, new MediaScannerConnection.OnScanCompletedListener() 
            {
                public void onScanCompleted(String path, Uri uri) 
                {
                    Log.i("ExternalStorage", "Scanned " + path + ":");
                    Log.i("ExternalStorage", "-> uri=" + uri);
                }
            });
        }
    }
    

提交回复
热议问题