I'm following this code to delete an apk file before downloading another one and then installing it
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
String fileName = getResources().getString(R.string.apkname) + ".apk";
destination += fileName;
final Uri uri = Uri.parse("file://" + destination);
File file = new File(destination);
if (file.canRead()) {
if (file.delete()) {
Toast.makeText(getApplicationContext(), "File deleted", Toast.LENGTH_LONG).show();
}
}
I'm finding the file, so I get to file.delete() and then I get the toast message, but when I check in downloads, the file is still there and I end up with multiple files with the same name, I can still use them with no issues, so it's like file.delete() did absolutely nothing.
For the record, I have WRITE_EXTERNAL_STORAGE permission in the manifest AND I request it in runtime too since I'm using sdkversion 25.
What's wrong?
Thanks in advance