Android file delete leaves empty placeholder in Gallery

后端 未结 9 705
再見小時候
再見小時候 2020-12-03 05:27

I insert an image via:

    ContentValues values = new ContentValues();   
    values.put(Images.Media.TITLE, filename);
    values.put(Images.Media.DATE_ADDE         


        
9条回答
  •  不思量自难忘°
    2020-12-03 05:47

    As stated in the comments, the accepted answer uses a lot of memory. While MediaScannerConnection doesn't have a "deleteFile" method, just pass in the the old file path to the "scanFile" method once you've deleted the file. The media scanner will rescan and remove the media.

    tested on N5. Android 4.4.

    EDIT: Other have stated this doesn't work on 4.2

    new AsyncTask(){
            @Override
            protected Void doInBackground(Void... params) {
                String filePath = recording.file.getAbsolutePath();
                recording.file.delete();
                MediaScannerConnection.scanFile(context,
                        new String[]{filePath}, null, null);
                return null;
            }
        }.execute();
    

提交回复
热议问题