I have used all of these functions:
deleteFile(FileName);
myFile.delete();
But none of these are deleting Files from sd card .I have tried my suggestions from stackoverflow but none of them are working. I have used the following code which appears to delete file from sd card but after some times the deleted files return back after some time. I donot know why .So plz help how to delete file from sd card.
public static boolean delete(final Context context, final File file) {
final String where = MediaStore.MediaColumns.DATA + "=?";
final String[] selectionArgs = new String[] {
file.getAbsolutePath()
};
final ContentResolver contentResolver = context.getContentResolver();
final Uri filesUri = MediaStore.Files.getContentUri("external");
contentResolver.delete(filesUri, where, selectionArgs);
if (file.exists()) {
contentResolver.delete(filesUri, where, selectionArgs);
}
return !file.exists();
}
I have used the following permissions
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />