Skip to content Skip to sidebar Skip to footer

Android Deleting Files Mediascannerconnection

I'm trying to delete some files or directories from the internal memory (ASUS TF101) using the commands File.delete(). However, using the Android File explorer I can see how the fi

Solution 1:

See the answer of manisha in this thread: Android file delete leaves empty placeholder in Gallery

In my case, it worked fine because i was saving a photo and then scanning it using the MediaScannerConnection, so when the scan finishes i have the URI of that file and then i can use the following code whitout problems.

getContentResolver().delete(imageUri, null, null);

Hope this works for you. This seems to be more suitable than forcing a SD Card remount by sending an intent to android system.

Solution 2:

I had the same problem, but I found the answear:

Android uses a media table to handle files. When you make changes to a file, you must update this table.

Try this:

sendBroadcast(newIntent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

Google doc: http://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_MOUNTED

Post a Comment for "Android Deleting Files Mediascannerconnection"