Android file delete leaves empty placeholder in Gallery

后端 未结 9 689
再見小時候
再見小時候 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 06:01

    taken from: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.html

    This worked for me ( tested on HTC Desire, Android 2.3)

    // Tell the media scanner about the new file so that it is
    // immediately available to the user.
    MediaScannerConnection.scanFile(this,new String[] { file.toString() }, null,
    new MediaScannerConnection.OnScanCompletedListener() {
    public void onScanCompleted(String path, Uri uri) {
    Log.i("ExternalStorage", "Scanned " + path + ":");
    Log.i("ExternalStorage", "-> uri=" + uri);
    }
    });
    
    0 讨论(0)
  • 2020-12-03 06:01
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      MediaScannerConnection.scanFile(context,new String[]{selectedVideoDelete}, null, null);
    } else {
      context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
    }
    
    0 讨论(0)
  • 2020-12-03 06:05

    Add this right after deleting a file:

    MediaScannerConnection.scanFile(context, arrayOf(imageURI.getPath()), null, null)

    :)

    0 讨论(0)
提交回复
热议问题